You've already forked comprehensive-rust
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:
@ -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>
|
||||
|
Reference in New Issue
Block a user