Skip to content

Commit

Permalink
improve Default trait example (rust-unofficial#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbolc authored Jul 26, 2021
1 parent c9897ab commit c23e006
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion idioms/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ different names, but there can only be one `Default` implementation per type.
use std::{path::PathBuf, time::Duration};

// note that we can simply auto-derive Default here.
#[derive(Default, Debug)]
#[derive(Default, Debug, PartialEq)]
struct MyConfiguration {
// Option defaults to None
output: Option<PathBuf>,
Expand All @@ -45,6 +45,13 @@ fn main() {
// do something with conf here
conf.check = true;
println!("conf = {:#?}", conf);

// partial initalization with default values, creates the same instance
let conf1 = MyConfiguration {
check: true,
..Default::default()
};
assert_eq!(conf, conf1);
}
```

Expand Down

0 comments on commit c23e006

Please sign in to comment.