Replace .map() + .flatten() with .and_then()

This commit is contained in:
Martin Ling 2024-09-20 18:36:10 +01:00 committed by John Whittington
parent 66851159e0
commit c9822becc3
2 changed files with 2 additions and 6 deletions

View file

@ -175,10 +175,7 @@ pub fn list_buses() -> Result<impl Iterator<Item = BusInfo>, Error> {
path: rh.path.to_owned(),
parent_path: parent_path.to_owned(),
busnum: rh.busnum,
controller_type: driver
.as_ref()
.map(|p| UsbControllerType::from_str(p))
.flatten(),
controller_type: driver.as_ref().and_then(|p| UsbControllerType::from_str(p)),
driver,
root_hub: rh,
})

View file

@ -404,8 +404,7 @@ fn parse_root_hub_id(s: &OsStr) -> Option<(u16, Option<String>)> {
.unwrap_or((0x0110, 0)); // default USB 1.1
let id = s
.get(i..)
.map(|v| v.strip_prefix("\\").map(|s| s.to_owned()))
.flatten();
.and_then(|v| v.strip_prefix("\\").map(|s| s.to_owned()));
Some((version, id))
}