Skip to content

Commit

Permalink
Use Cycle iterator for Frames sub rule parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Aug 22, 2020
1 parent 9d110a1 commit 35158e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/frames.rs
Expand Up @@ -45,7 +45,7 @@ impl<'i> TryFrom<Pair<'i, Rule>> for Frames {
Frames::default(),
pair,
Rule::Frames,
&[Self::parse_frame as SubRuleFn<_>],
Iterator::cycle([Self::parse_frame as SubRuleFn<_>].iter()),
)
}
}
16 changes: 5 additions & 11 deletions src/object_data_parser.rs
Expand Up @@ -21,17 +21,11 @@ impl ObjectDataParser {
TBuilder: 'static,
{
if pair.as_rule() == rule_expected {
let mut pairs = pair.into_inner();
subrule_fns
.into_iter()
.try_fold(builder, |builder, subrule_fn| {
pairs
.next()
.ok_or(Error::Grammar {
rule_expected: Rule::Header,
pair_found: None,
})
.and_then(|pair| subrule_fn(builder, pair))
let pairs = pair.into_inner();
pairs
.zip(subrule_fns.into_iter())
.try_fold(builder, |builder, (pair, subrule_fn)| {
subrule_fn(builder, pair)
})
} else {
Err(Error::Grammar {
Expand Down

0 comments on commit 35158e4

Please sign in to comment.