You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-24 17:56:45 +02:00
Comprehensive Rust v2 (#1073)
I've taken some work by @fw-immunant and others on the new organization of the course and condensed it into a form amenable to a text editor and some computational analysis. You can see the inputs in `course.py` but the interesting bits are the output: `outline.md` and `slides.md`. The idea is to break the course into more, smaller segments with exercises at the ends and breaks in between. So `outline.md` lists the segments, their duration, and sums those durations up per-day. It shows we're about an hour too long right now! There are more details of the segments in `slides.md`, or you can see mostly the same stuff in `course.py`. This now contains all of the content from the v1 course, ensuring both that we've covered everything and that we'll have somewhere to redirect every page. Fixes #1082. Fixes #1465. --------- Co-authored-by: Nicole LeGare <dlegare.1001@gmail.com> Co-authored-by: Martin Geisler <mgeisler@google.com>
This commit is contained in:
committed by
GitHub
parent
ea204774b6
commit
6d19292f16
32
src/control-flow-basics/functions.md
Normal file
32
src/control-flow-basics/functions.md
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
minutes: 3
|
||||
---
|
||||
|
||||
# Functions
|
||||
|
||||
<!-- mdbook-xgettext: skip -->
|
||||
```rust,editable
|
||||
fn gcd(a: u32, b: u32) -> u32 {
|
||||
if b > 0 {
|
||||
gcd(b, a % b)
|
||||
} else {
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("gcd: {}", gcd(143, 52));
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
* Declaration parameters are followed by a type (the reverse of some programming languages), then a return type.
|
||||
* The last expression in a function body (or any block) becomes the return value. Simply omit the `;` at the end of the expression.
|
||||
The `return` keyword can be used for early return, but the "bare value" form is idiomatic at the end of a function (refactor `gcd` to use a `return`).
|
||||
* Some functions have no return value, and return the 'unit type', `()`. The compiler will infer this if the `-> ()` return type is omitted.
|
||||
* Overloading is not supported -- each function has a single implementation.
|
||||
* Always takes a fixed number of parameters. Default arguments are not supported. Macros can be used to support variadic functions.
|
||||
* Always takes a single set of parameter types. These types can be generic, which will be covered later.
|
||||
|
||||
</details>
|
Reference in New Issue
Block a user