diff options
author | Daniel Eades <danieleades@hotmail.com> | 2021-12-27 11:44:14 +0000 |
---|---|---|
committer | Daniel Eades <danieleades@hotmail.com> | 2021-12-29 12:54:40 +0000 |
commit | deb4b9caeeb401eb8183db4fa106112ef1c11f29 (patch) | |
tree | 3876bcaf31a5c1547af75dfeabb5a76a2a5bf2fd /src/path | |
parent | 8092fc0290db443f1cdb62e09b9854fae2a7d31a (diff) |
use 'if-else' rather than 'match' for single matches
Diffstat (limited to 'src/path')
-rw-r--r-- | src/path/mod.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/path/mod.rs b/src/path/mod.rs index 24a6325..d78d07d 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -128,13 +128,13 @@ impl Expression { }, Expression::Child(ref expr, ref key) => match expr.get_mut_forcibly(root) { - Some(value) => match value.kind { - ValueKind::Table(ref mut map) => Some( - map.entry(key.clone()) - .or_insert_with(|| Value::new(None, ValueKind::Nil)), - ), - - _ => { + Some(value) => { + if let ValueKind::Table(ref mut map) = value.kind { + Some( + map.entry(key.clone()) + .or_insert_with(|| Value::new(None, ValueKind::Nil)), + ) + } else { *value = Map::<String, Value>::new().into(); if let ValueKind::Table(ref mut map) = value.kind { @@ -146,7 +146,7 @@ impl Expression { unreachable!(); } } - }, + } _ => None, }, @@ -221,17 +221,13 @@ impl Expression { Expression::Child(ref expr, ref key) => { if let Some(parent) = expr.get_mut_forcibly(root) { - match parent.kind { - ValueKind::Table(_) => { - Expression::Identifier(key.clone()).set(parent, value); - } + if let ValueKind::Table(_) = parent.kind { + Expression::Identifier(key.clone()).set(parent, value); + } else { + // Didn't find a table. Oh well. Make a table and do this anyway + *parent = Map::<String, Value>::new().into(); - _ => { - // Didn't find a table. Oh well. Make a table and do this anyway - *parent = Map::<String, Value>::new().into(); - - Expression::Identifier(key.clone()).set(parent, value); - } + Expression::Identifier(key.clone()).set(parent, value); } } } |