use if-let
This commit is contained in:
parent
a5c55115cf
commit
6c8298aeec
1 changed files with 17 additions and 18 deletions
35
src/main.rs
35
src/main.rs
|
@ -309,26 +309,25 @@ struct Message {
|
||||||
async fn handle_list(conf: Config, args: List) -> Result<()> {
|
async fn handle_list(conf: Config, args: List) -> Result<()> {
|
||||||
// Use provided zones or list all in config
|
// Use provided zones or list all in config
|
||||||
let known_zones: HashSet<_> = conf.zone.values().map(|zone| &zone.id).collect();
|
let known_zones: HashSet<_> = conf.zone.values().map(|zone| &zone.id).collect();
|
||||||
let zones: Vec<_> = match args.zones {
|
let zones: Vec<_> = if let Some(zones) = args.zones {
|
||||||
Some(zones) => {
|
// These zones may be human readable. Map them to zone IDs.
|
||||||
// These zones may be human readable. Map them to zone IDs.
|
zones
|
||||||
zones
|
.into_iter()
|
||||||
.into_iter()
|
.filter_map(|maybe_zone_id| {
|
||||||
.filter_map(|maybe_zone_id| {
|
if known_zones.contains(&maybe_zone_id) {
|
||||||
if known_zones.contains(&maybe_zone_id) {
|
return Some(maybe_zone_id);
|
||||||
return Some(maybe_zone_id);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(zone) = conf.zone.get(&maybe_zone_id) {
|
if let Some(zone) = conf.zone.get(&maybe_zone_id) {
|
||||||
return Some(zone.id.clone());
|
return Some(zone.id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
warn!("Unknown zone {maybe_zone_id}, skipping");
|
warn!("Unknown zone {maybe_zone_id}, skipping");
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
} else {
|
||||||
None => known_zones.into_iter().cloned().collect(),
|
known_zones.into_iter().cloned().collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut output = BTreeMap::new();
|
let mut output = BTreeMap::new();
|
||||||
|
|
Loading…
Reference in a new issue