summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Eades <danieleades@hotmail.com>2021-12-27 11:44:14 +0000
committerDaniel Eades <danieleades@hotmail.com>2021-12-29 12:54:40 +0000
commitdeb4b9caeeb401eb8183db4fa106112ef1c11f29 (patch)
tree3876bcaf31a5c1547af75dfeabb5a76a2a5bf2fd
parent8092fc0290db443f1cdb62e09b9854fae2a7d31a (diff)
use 'if-else' rather than 'match' for single matches
-rw-r--r--src/file/source/file.rs41
-rw-r--r--src/path/mod.rs32
2 files changed, 34 insertions, 39 deletions
diff --git a/src/file/source/file.rs b/src/file/source/file.rs
index 9bd3ddd..017e0d3 100644
--- a/src/file/source/file.rs
+++ b/src/file/source/file.rs
@@ -35,29 +35,28 @@ impl FileSourceFile {
// First check for an _exact_ match
if filename.is_file() {
- return match format_hint {
- Some(format) => Ok((filename, Box::new(format))),
- None => {
- for (format, extensions) in ALL_EXTENSIONS.iter() {
- if extensions.contains(
- &filename
- .extension()
- .unwrap_or_default()
- .to_string_lossy()
- .as_ref(),
- ) {
- return Ok((filename, Box::new(*format)));
- }
+ return if let Some(format) = format_hint {
+ Ok((filename, Box::new(format)))
+ } else {
+ for (format, extensions) in ALL_EXTENSIONS.iter() {
+ if extensions.contains(
+ &filename
+ .extension()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .as_ref(),
+ ) {
+ return Ok((filename, Box::new(*format)));
}
-
- Err(Box::new(io::Error::new(
- io::ErrorKind::NotFound,
- format!(
- "configuration file \"{}\" is not of a registered file format",
- filename.to_string_lossy()
- ),
- )))
}
+
+ Err(Box::new(io::Error::new(
+ io::ErrorKind::NotFound,
+ format!(
+ "configuration file \"{}\" is not of a registered file format",
+ filename.to_string_lossy()
+ ),
+ )))
};
}
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);
}
}
}