From f1a5808e6722e5b68ad68c91c8094f63a50db603 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Mon, 13 Jan 2025 14:25:53 +0100 Subject: [PATCH] replace match statements with ? operator When possible. Signed-off-by: Maximiliano Sandoval --- pbs-config/src/acl.rs | 10 ++-------- pbs-datastore/src/hierarchy.rs | 7 +++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs index e8690560..aca1f68f 100644 --- a/pbs-config/src/acl.rs +++ b/pbs-config/src/acl.rs @@ -342,10 +342,7 @@ impl AclTree { let mut node = &self.root; for outer in path { for comp in outer.split('/') { - node = match node.children.get(comp) { - Some(n) => n, - None => return None, - }; + node = node.children.get(comp)?; } } Some(node) @@ -355,10 +352,7 @@ impl AclTree { let mut node = &mut self.root; for outer in path { for comp in outer.split('/') { - node = match node.children.get_mut(comp) { - Some(n) => n, - None => return None, - }; + node = node.children.get_mut(comp)?; } } Some(node) diff --git a/pbs-datastore/src/hierarchy.rs b/pbs-datastore/src/hierarchy.rs index 8b7af038..25a4d382 100644 --- a/pbs-datastore/src/hierarchy.rs +++ b/pbs-datastore/src/hierarchy.rs @@ -417,10 +417,9 @@ impl Iterator for ListNamespacesRecursive { if state.is_empty() { return None; // there's a state but it's empty -> we're all done } - let iter = match state.last_mut() { - Some(iter) => iter, - None => return None, // unexpected, should we just unwrap? - }; + // should we just unwrap on None? + let iter = state.last_mut()?; + match iter.next() { Some(Ok(ns)) => { if state.len() < self.max_depth as usize {