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 authored and GitHub committed 2023-01-23 11:32:46 +00:00
1 parent 356d1cec19
commit 8dd749da60
1 file changed
+14
+14
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>