Skip to content

Commit 757fbd6

Browse files
committed
use option instead of (bool, option)
1 parent 3ba1e65 commit 757fbd6

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/state_machine.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,17 @@ pub(crate) struct Match<'m> {
160160
pub params: HashMap<&'static str, &'m str>,
161161
}
162162

163-
#[derive(Default)]
164-
struct StartParse {
165-
should_start: bool,
166-
name: Option<&'static str>,
167-
}
168-
169163
pub(crate) struct StateMachine {
170164
states: Vec<State>,
171-
start_parse: Vec<StartParse>,
165+
start_parse: Vec<Option<&'static str>>,
172166
end_parse: Vec<bool>,
173167
}
174168

175169
impl StateMachine {
176170
pub(crate) fn new() -> Self {
177171
Self {
178172
states: vec![State::new(0, CharacterSet::new())],
179-
start_parse: vec![StartParse::default()],
173+
start_parse: vec![None],
180174
end_parse: vec![false],
181175
}
182176
}
@@ -209,7 +203,7 @@ impl StateMachine {
209203
let state = State::new(index, expected);
210204

211205
self.states.push(state);
212-
self.start_parse.push(StartParse::default());
206+
self.start_parse.push(None);
213207
self.end_parse.push(false);
214208
index
215209
}
@@ -228,9 +222,7 @@ impl StateMachine {
228222
/// Mark that the index in the state machine is a state to start parsing a dynamic
229223
/// segment.
230224
pub(crate) fn start_parse(&mut self, index: usize, name: &'static str) {
231-
let parse = &mut self.start_parse[index];
232-
parse.should_start = true;
233-
parse.name = Some(name);
225+
self.start_parse[index] = Some(name);
234226
}
235227

236228
/// Mark that the index in the state machine is a state to stop parsing a dynamic
@@ -326,8 +318,8 @@ impl StateMachine {
326318
) {
327319
let start_parse = &self.start_parse[next_state];
328320

329-
if traversal.segment_start.is_none() && start_parse.should_start {
330-
traversal.set_segment_start(pos, start_parse.name.unwrap());
321+
if traversal.segment_start.is_none() && start_parse.is_some() {
322+
traversal.set_segment_start(pos, start_parse.unwrap());
331323
}
332324
if traversal.segment_start.is_some()
333325
&& self.end_parse[current_state]

0 commit comments

Comments
 (0)