1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-16 22:27:34 +02:00

Update field-shorthand.md (#227)

Introducing `Self` type that students can encounter in many places and nice to use. It is only mentioned later in the course, but it is not defined currently.
This commit is contained in:
Igor Petruk
2023-01-23 11:32:46 +00:00
committed by GitHub
parent 356d1cec19
commit 8dd749da60

View File

@ -21,3 +21,17 @@ fn main() {
println!("{peter:?}");
}
```
<details>
The `new` function could be written using `Self` as a type, as it is interchangeable with the struct type name
```rust,ignore
impl Person {
fn new(name: String, age: u8) -> Self {
Self { name, age }
}
}
```
</details>