summaryrefslogtreecommitdiffstats
path: root/src/path
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
committerRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
commit14224be23dc2f253a240b85214927d97e1160669 (patch)
tree6f5b02b26aef5cf37bb14f32b9048165b67109ce /src/path
parent71f4b182d1e56febda64bd620ae0e0f65de333cd (diff)
Remove ConfigResult; close #36
Diffstat (limited to 'src/path')
-rw-r--r--src/path/mod.rs121
1 files changed, 58 insertions, 63 deletions
diff --git a/src/path/mod.rs b/src/path/mod.rs
index 046888e..258c4c4 100644
--- a/src/path/mod.rs
+++ b/src/path/mod.rs
@@ -58,87 +58,78 @@ impl Expression {
}
}
- Expression::Subscript(expr, index) => {
- match expr.get(root) {
- Some(value) => {
- match value.kind {
- ValueKind::Array(ref array) => {
- let index = sindex_to_uindex(index, array.len());
-
- if index >= array.len() {
- None
- } else {
- Some(&array[index])
- }
- }
+ Expression::Subscript(expr, index) => match expr.get(root) {
+ Some(value) => match value.kind {
+ ValueKind::Array(ref array) => {
+ let index = sindex_to_uindex(index, array.len());
- _ => None,
+ if index >= array.len() {
+ None
+ } else {
+ Some(&array[index])
}
}
_ => None,
- }
- }
+ },
+
+ _ => None,
+ },
}
}
pub fn get_mut<'a>(&self, root: &'a mut Value) -> Option<&'a mut Value> {
match *self {
- Expression::Identifier(ref id) => {
- match root.kind {
- ValueKind::Table(ref mut map) => {
- Some(map.entry(id.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
- }
-
- _ => None,
- }
- }
+ Expression::Identifier(ref id) => match root.kind {
+ ValueKind::Table(ref mut map) => Some(
+ map.entry(id.clone())
+ .or_insert_with(|| Value::new(None, ValueKind::Nil)),
+ ),
+
+ _ => None,
+ },
+
+ Expression::Child(ref expr, ref key) => match expr.get_mut(root) {
+ Some(value) => match value.kind {
+ ValueKind::Table(ref mut map) => Some(
+ map.entry(key.clone())
+ .or_insert_with(|| Value::new(None, ValueKind::Nil)),
+ ),
- Expression::Child(ref expr, ref key) => {
- match expr.get_mut(root) {
- Some(value) => {
- match value.kind {
- ValueKind::Table(ref mut map) => {
- Some(map.entry(key.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
- }
-
- _ => {
- *value = HashMap::<String, Value>::new().into();
+ _ => {
+ *value = HashMap::<String, Value>::new().into();
- if let ValueKind::Table(ref mut map) = value.kind {
- Some(map.entry(key.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
- } else {
- unreachable!();
- }
- }
+ if let ValueKind::Table(ref mut map) = value.kind {
+ Some(
+ map.entry(key.clone())
+ .or_insert_with(|| Value::new(None, ValueKind::Nil)),
+ )
+ } else {
+ unreachable!();
}
}
+ },
- _ => None,
- }
- }
+ _ => None,
+ },
- Expression::Subscript(ref expr, index) => {
- match expr.get_mut(root) {
- Some(value) => {
- match value.kind {
- ValueKind::Array(ref mut array) => {
- let index = sindex_to_uindex(index, array.len());
-
- if index >= array.len() {
- array.resize((index + 1) as usize, Value::new(None, ValueKind::Nil));
- }
+ Expression::Subscript(ref expr, index) => match expr.get_mut(root) {
+ Some(value) => match value.kind {
+ ValueKind::Array(ref mut array) => {
+ let index = sindex_to_uindex(index, array.len());
- Some(&mut array[index])
- }
-
- _ => None,
+ if index >= array.len() {
+ array.resize((index + 1) as usize, Value::new(None, ValueKind::Nil));
}
+
+ Some(&mut array[index])
}
_ => None,
- }
- }
+ },
+
+ _ => None,
+ },
}
}
@@ -147,7 +138,7 @@ impl Expression {
Expression::Identifier(ref id) => {
// Ensure that root is a table
match root.kind {
- ValueKind::Table(_) => { }
+ ValueKind::Table(_) => {}
_ => {
*root = HashMap::<String, Value>::new().into();
@@ -158,7 +149,8 @@ impl Expression {
ValueKind::Table(ref incoming_map) => {
// Pull out another table
let mut target = if let ValueKind::Table(ref mut map) = root.kind {
- map.entry(id.clone()).or_insert_with(|| HashMap::<String, Value>::new().into())
+ map.entry(id.clone())
+ .or_insert_with(|| HashMap::<String, Value>::new().into())
} else {
unreachable!();
};
@@ -202,7 +194,10 @@ impl Expression {
let uindex = sindex_to_uindex(index, array.len());
if uindex >= array.len() {
- array.resize((uindex + 1) as usize, Value::new(None, ValueKind::Nil));
+ array.resize(
+ (uindex + 1) as usize,
+ Value::new(None, ValueKind::Nil),
+ );
}
array[uindex] = value.clone();