Skip to contentSkip to conversation

bcachefs-tools: replace multiple if with match to improve readability

PATCH In review Integral 1 participant 3 messages Oct 27, 2024 – Nov 27, 2024

lore
Share & tools
lore

Integral

author
#0 lore raw

PATCH 1/1 bcachefs-tools: replace multiple if with match to improve readability

Replace multiple if expressions with match in Rust code to improve readability.

---
 bch_bindgen/src/lib.rs | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
bch_bindgen/src/lib.rs +5 -10
index b68f2d9b..7d65f17a 100644
@@ -173,16 +173,11 @@ impl FromStr for c::bpos {
     type Err = BchToolsErr;
 
     fn from_str(s: &str) -> Result<Self, Self::Err> {
-        if s == "POS_MIN" {
-            return Ok(POS_MIN);
-        }
-
-        if s == "POS_MAX" {
-            return Ok(POS_MAX);
-        }
-
-        if s == "SPOS_MAX" {
-            return Ok(SPOS_MAX);
+        match s {
+            "POS_MIN" => return Ok(POS_MIN),
+            "POS_MAX" => return Ok(POS_MAX),
+            "SPOS_MAX" => return Ok(SPOS_MAX),
+            _ => (),
         }
 
         let mut fields = s.split(':');

--
2.47.0

author
#1 lore raw

Hi, Kent

Give you a friendly ping :)