Skip to content

Commit 1e7834d

Browse files
committed
clippy: fix unwrap_or with call to new()
``` src/config.rs:119:20: 119:97 warning: use of `unwrap_or` followed by a call to `new`, #[warn(or_fun_call)] on by default src/config.rs:119 names: d.read_struct_field("names", 0, Decodable::decode).unwrap_or(BTreeSet::new()), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/config.rs:119:20: 119:97 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call src/config.rs:119:20: 119:97 help: try this src/config.rs: names: d.read_struct_field("names", 0, Decodable::decode).unwrap_or_default(), ``` Note that in order to call `unwrap_or_default` we need to convert the `Result` type to `Option` via `ok()`. Signed-off-by: Paul Osborne <[email protected]>
1 parent 62872ab commit 1e7834d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Decodable for PinConfig {
116116
}
117117
})
118118
.unwrap_or(sysfs_gpio::Direction::In), // default: In
119-
names: d.read_struct_field("names", 0, Decodable::decode).unwrap_or(BTreeSet::new()),
119+
names: d.read_struct_field("names", 0, Decodable::decode).ok().unwrap_or_default(),
120120
export: d.read_struct_field("export", 0, Decodable::decode).unwrap_or(true),
121121
active_low: d.read_struct_field("active_low", 0, Decodable::decode).unwrap_or(false),
122122
})

0 commit comments

Comments
 (0)