diff --git a/src/_keyword_impls.rs b/src/_keyword_impls.rs index 7d57578..1e75e9b 100644 --- a/src/_keyword_impls.rs +++ b/src/_keyword_impls.rs @@ -1,63 +1,65 @@ use std::slice::Iter; use std::str::Chars; -struct _StringIteratorImpl<'a> { - orig: Chars<'a>, -} - -impl crate::_KeywordComparatorIterator for _StringIteratorImpl<'_> { - fn consume(&mut self, e: &char) -> bool { - return self.orig.next().is_some_and(|a| a.eq(e)); +impl crate::_KeywordComparatorIterator for Chars<'_> { + fn consume(&mut self, e: char) -> bool { + return self.next().is_some_and(|a| a == e); } } impl crate::_Keyword for &str { - fn startComparation(&self, expectedLen: usize) -> Option> { + fn startComparation( + &self, + expectedLen: usize, + ) -> Option> { if (self.len() != expectedLen) { return Option::None; } - return Option::Some(_StringIteratorImpl { orig: self.chars() }); + return Option::Some(self.chars()); } } impl crate::_Keyword for &String { - fn startComparation(&self, expectedLen: usize) -> Option> { + fn startComparation( + &self, + expectedLen: usize, + ) -> Option> { if (self.len() != expectedLen) { return Option::None; } - return Option::Some(_StringIteratorImpl { orig: self.chars() }); + return Option::Some(self.chars()); } } - -struct _ArrayIteratorImpl<'a, T> { - orig: Iter<'a, T>, -} - -impl crate::_KeywordComparatorIterator for _ArrayIteratorImpl<'_, T> { - fn consume(&mut self, e: &T) -> bool { - return self.orig.next().is_some_and(|a| a == e); +impl crate::_KeywordComparatorIterator for Iter<'_, T> { + fn consume(&mut self, e: T) -> bool { + return self.next().is_some_and(|a| a.eq(&e)); } } impl crate::_Keyword for &[T] { - fn startComparation(&self, expectedLen: usize) -> Option> { + fn startComparation( + &self, + expectedLen: usize, + ) -> Option> { if (self.len() != expectedLen) { return Option::None; } - return Option::Some(_ArrayIteratorImpl { orig: self.iter() }); + return Option::Some(self.iter()); } } - impl crate::_Keyword for &[T; SZ] { - fn startComparation(&self, expectedLen: usize) -> Option> { + fn startComparation( + &self, + expectedLen: usize, + ) -> Option> { if (self.len() != expectedLen) { return Option::None; } - return Option::Some(_ArrayIteratorImpl { orig: self.iter() }); + return Option::Some(self.iter()); } } diff --git a/src/lib.rs b/src/lib.rs index 44abaaa..ddd803d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ mod _keyword_impls; pub trait Predicate { - fn check(&mut self, chr: &C) -> bool; + fn check(&mut self, chr: C) -> bool; } -impl Predicate for fn(&C) -> bool { - fn check(&mut self, chr: &C) -> bool { +impl Predicate for fn(C) -> bool { + fn check(&mut self, chr: C) -> bool { return self(chr); } } @@ -13,7 +13,7 @@ impl Predicate for fn(&C) -> bool { pub trait Pos {} pub trait _KeywordComparatorIterator { - fn consume(&mut self, c: &C) -> bool; + fn consume(&mut self, c: C) -> bool; } pub trait _Keyword {