mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-18 05:37:52 +02:00
Default trait slides cleanup (#1038)
* Default trait slides cleanup * Update src/traits/default.md Co-authored-by: Martin Geisler <martin@geisler.net> --------- Co-authored-by: Martin Geisler <martin@geisler.net>
This commit is contained in:
parent
14bfd7b723
commit
a7a9ee84b4
@ -20,12 +20,12 @@ impl Default for Implemented {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let default_struct: Derived = Default::default();
|
||||
let default_struct = Derived::default();
|
||||
println!("{default_struct:#?}");
|
||||
|
||||
let almost_default_struct = Derived {
|
||||
y: "Y is set!".into(),
|
||||
..Default::default()
|
||||
..Derived::default()
|
||||
};
|
||||
println!("{almost_default_struct:#?}");
|
||||
|
||||
@ -43,7 +43,9 @@ fn main() {
|
||||
* Standard Rust types often implement `Default` with reasonable values (e.g. `0`, `""`, etc).
|
||||
* The partial struct copy works nicely with default.
|
||||
* Rust standard library is aware that types can implement `Default` and provides convenience methods that use it.
|
||||
* the `..` syntax is called [struct update syntax][2]
|
||||
|
||||
</details>
|
||||
|
||||
[1]: https://doc.rust-lang.org/std/default/trait.Default.html
|
||||
[2]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
|
Loading…
x
Reference in New Issue
Block a user