1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-02 17:48:47 +02:00

Speaker notes for 6.5 Functions

Adds speaker notes covering functions basics (declaration parameters, return values, the 'unit' type.
This commit is contained in:
Robin Stringer 2023-01-19 12:16:43 +00:00 committed by GitHub
parent eb9f873466
commit 2d4340f3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,3 +29,12 @@ fn fizzbuzz_to(n: u32) { // `-> ()` is normally omitted
}
}
```
<details>
* We refer in `main` to a function written below. Neither forward declarations nor headers are necessary.
* Declaration parameters are followed by a type (the reverse of some programming languages), then a return type.
* The last expression in a function body becomes the return value. Simply omit the `;` at the end of the expression.
* Some functions have no return value, and output the 'unit type', `()`. The compiler will infer this if the `-> ()` return type is omitted.
</details>