Skip to content

Commit c397a10

Browse files
committed
refactor(path): Flatten with let-else
1 parent 8323fa2 commit c397a10

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/path/mod.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,56 +107,55 @@ impl Expression {
107107
if !matches!(root.kind, ValueKind::Table(_)) {
108108
*root = Map::<String, Value>::new().into();
109109
}
110-
111-
if let ValueKind::Table(ref mut map) = root.kind {
112-
map.entry(key.clone())
113-
.or_insert_with(|| Value::new(None, ValueKind::Nil))
114-
} else {
110+
let ValueKind::Table(ref mut map) = root.kind else {
115111
unreachable!()
116-
}
112+
};
113+
114+
map.entry(key.clone())
115+
.or_insert_with(|| Value::new(None, ValueKind::Nil))
117116
}
118117

119118
Self::Child(ref expr, ref key) => {
120119
let child = expr.get_mut_forcibly(root);
120+
121121
if !matches!(child.kind, ValueKind::Table(_)) {
122122
*child = Map::<String, Value>::new().into();
123123
}
124-
125-
if let ValueKind::Table(ref mut map) = child.kind {
126-
map.entry(key.clone())
127-
.or_insert_with(|| Value::new(None, ValueKind::Nil))
128-
} else {
124+
let ValueKind::Table(ref mut map) = child.kind else {
129125
unreachable!()
130-
}
126+
};
127+
128+
map.entry(key.clone())
129+
.or_insert_with(|| Value::new(None, ValueKind::Nil))
131130
}
132131

133132
Self::Subscript(ref expr, index) => {
134133
let child = expr.get_mut_forcibly(root);
134+
135135
if !matches!(child.kind, ValueKind::Array(_)) {
136136
*child = Vec::<Value>::new().into();
137137
}
138+
let ValueKind::Array(ref mut array) = child.kind else {
139+
unreachable!()
140+
};
138141

139-
if let ValueKind::Array(ref mut array) = child.kind {
140-
let uindex = match abs_index(index, array.len()) {
141-
Ok(uindex) => {
142-
if uindex >= array.len() {
143-
array.resize(uindex + 1, Value::new(None, ValueKind::Nil));
144-
}
145-
uindex
142+
let uindex = match abs_index(index, array.len()) {
143+
Ok(uindex) => {
144+
if uindex >= array.len() {
145+
array.resize(uindex + 1, Value::new(None, ValueKind::Nil));
146146
}
147-
Err(insertion) => {
148-
array.splice(
149-
0..0,
150-
(0..insertion).map(|_| Value::new(None, ValueKind::Nil)),
151-
);
152-
0
153-
}
154-
};
147+
uindex
148+
}
149+
Err(insertion) => {
150+
array.splice(
151+
0..0,
152+
(0..insertion).map(|_| Value::new(None, ValueKind::Nil)),
153+
);
154+
0
155+
}
156+
};
155157

156-
&mut array[uindex]
157-
} else {
158-
unreachable!()
159-
}
158+
&mut array[uindex]
160159
}
161160
}
162161
}

0 commit comments

Comments
 (0)