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.
pull/144/head
Riley Shea 3 years ago committed by GitHub
parent e333d15258
commit 4017a73d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,14 +19,16 @@ different names, but there can only be one `Default` implementation per type.
## Example
```rust,ignore
```rust
use std::{path::PathBuf, time::Duration};
// note that we can simply auto-derive Default here.
#[derive(Default)]
#[derive(Default, Debug)]
struct MyConfiguration {
// Option defaults to None
output: Option<Path>,
output: Option<PathBuf>,
// Vecs default to empty vector
search_path: Vec<Path>,
search_path: Vec<PathBuf>,
// Duration defaults to zero time
timeout: Duration,
// bool defaults to false
@ -40,7 +42,9 @@ impl MyConfiguration {
fn main() {
// construct a new instance with default values
let mut conf = MyConfiguration::default();
// do somthing with conf here
// do something with conf here
conf.check = true;
println!("conf = {:#?}", conf);
}
```

Loading…
Cancel
Save