Skip to content

Commit 4017a73

Browse files
authored
Fix default idiom example (#134)
Before this change, the example code doesn't run on the current rust stable release(1.49). This is because `Path` inherently has a u8 that requires the sized trait which requires either statics or replacing Path with PathBuf. After this change, the example code will run "as-is" without warnings or errors.
1 parent e333d15 commit 4017a73

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

idioms/default.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ different names, but there can only be one `Default` implementation per type.
1919

2020
## Example
2121

22-
```rust,ignore
22+
```rust
23+
use std::{path::PathBuf, time::Duration};
24+
2325
// note that we can simply auto-derive Default here.
24-
#[derive(Default)]
26+
#[derive(Default, Debug)]
2527
struct MyConfiguration {
2628
// Option defaults to None
27-
output: Option<Path>,
29+
output: Option<PathBuf>,
2830
// Vecs default to empty vector
29-
search_path: Vec<Path>,
31+
search_path: Vec<PathBuf>,
3032
// Duration defaults to zero time
3133
timeout: Duration,
3234
// bool defaults to false
@@ -40,7 +42,9 @@ impl MyConfiguration {
4042
fn main() {
4143
// construct a new instance with default values
4244
let mut conf = MyConfiguration::default();
43-
// do somthing with conf here
45+
// do something with conf here
46+
conf.check = true;
47+
println!("conf = {:#?}", conf);
4448
}
4549
```
4650

0 commit comments

Comments
 (0)