mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-09 09:11:50 +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:
parent
356d1cec19
commit
8dd749da60
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user