diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-10-23 00:28:56 -0400 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-10-23 00:28:56 -0400 |
| commit | 60f8e11769864befc1f116f5f2896cdbf16609f1 (patch) | |
| tree | f834eed1ec752a7c0ec0121427212bac329fce4a | |
| parent | 8625d6afe75e1915c4d568664d7deca4b3c5fae9 (diff) | |
| download | mon-60f8e11769864befc1f116f5f2896cdbf16609f1.tar.gz | |
clone iterator in OneOf
| -rw-r--r-- | src/lib.rs | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -1,4 +1,11 @@ -use core::{cmp::PartialEq, fmt, iter::Iterator, marker::Sized, ops::Range}; +use core::{ + clone::Clone, + cmp::PartialEq, + fmt, + iter::{IntoIterator, Iterator}, + marker::Sized, + ops::Range, +}; use crate::{ input::{Character, Input, InputIter}, @@ -427,7 +434,7 @@ impl<I, It> Parser<I> for OneOf<It> where I: Input, I::Item: PartialEq<It::Item>, - It: Iterator, + It: IntoIterator + Clone, { type Output = I::Item; @@ -437,9 +444,13 @@ where ) -> ParserResult<I, Self::Output, OM, EM> { Tracer::trace("oneof", it.clone()); + let start = it.clone(); + match it.next() { - Some((_, item)) if self.it.any(|i| item == i) => Ok((it, OM::bind(|| item))), - _ => Err(EM::bind(|| it)), + Some((_, item)) if self.it.clone().into_iter().any(|i| item == i) => { + Ok((it, OM::bind(|| item))) + } + _ => Err(EM::bind(|| start)), } } } @@ -448,7 +459,7 @@ pub fn one_of<I, It>(it: It) -> impl Parser<I, Output = I::Item> where I: Input, I::Item: PartialEq<It::Item>, - It: Iterator, + It: IntoIterator + Clone, { OneOf { it } } |
