summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-23 00:28:56 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-23 00:28:56 -0400
commit60f8e11769864befc1f116f5f2896cdbf16609f1 (patch)
treef834eed1ec752a7c0ec0121427212bac329fce4a /src
parent8625d6afe75e1915c4d568664d7deca4b3c5fae9 (diff)
downloadmon-60f8e11769864befc1f116f5f2896cdbf16609f1.tar.gz
clone iterator in OneOf
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 83ead73..1de814c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 }
}