Simplified _Keyword impls
This commit is contained in:
parent
dd86157e7e
commit
525ba5d370
@ -1,63 +1,65 @@
|
||||
use std::slice::Iter;
|
||||
use std::str::Chars;
|
||||
|
||||
struct _StringIteratorImpl<'a> {
|
||||
orig: Chars<'a>,
|
||||
}
|
||||
|
||||
impl crate::_KeywordComparatorIterator<char> for _StringIteratorImpl<'_> {
|
||||
fn consume(&mut self, e: &char) -> bool {
|
||||
return self.orig.next().is_some_and(|a| a.eq(e));
|
||||
impl crate::_KeywordComparatorIterator<char> for Chars<'_> {
|
||||
fn consume(&mut self, e: char) -> bool {
|
||||
return self.next().is_some_and(|a| a == e);
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::_Keyword<char> for &str {
|
||||
fn startComparation(&self, expectedLen: usize) -> Option<impl crate::_KeywordComparatorIterator<char>> {
|
||||
fn startComparation(
|
||||
&self,
|
||||
expectedLen: usize,
|
||||
) -> Option<impl crate::_KeywordComparatorIterator<char>> {
|
||||
if (self.len() != expectedLen) {
|
||||
return Option::None;
|
||||
}
|
||||
|
||||
return Option::Some(_StringIteratorImpl { orig: self.chars() });
|
||||
return Option::Some(self.chars());
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::_Keyword<char> for &String {
|
||||
fn startComparation(&self, expectedLen: usize) -> Option<impl crate::_KeywordComparatorIterator<char>> {
|
||||
fn startComparation(
|
||||
&self,
|
||||
expectedLen: usize,
|
||||
) -> Option<impl crate::_KeywordComparatorIterator<char>> {
|
||||
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<T: PartialEq> crate::_KeywordComparatorIterator<T> for _ArrayIteratorImpl<'_, T> {
|
||||
fn consume(&mut self, e: &T) -> bool {
|
||||
return self.orig.next().is_some_and(|a| a == e);
|
||||
impl<T: PartialEq> crate::_KeywordComparatorIterator<T> for Iter<'_, T> {
|
||||
fn consume(&mut self, e: T) -> bool {
|
||||
return self.next().is_some_and(|a| a.eq(&e));
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq> crate::_Keyword<T> for &[T] {
|
||||
fn startComparation(&self, expectedLen: usize) -> Option<impl crate::_KeywordComparatorIterator<T>> {
|
||||
fn startComparation(
|
||||
&self,
|
||||
expectedLen: usize,
|
||||
) -> Option<impl crate::_KeywordComparatorIterator<T>> {
|
||||
if (self.len() != expectedLen) {
|
||||
return Option::None;
|
||||
}
|
||||
|
||||
return Option::Some(_ArrayIteratorImpl { orig: self.iter() });
|
||||
return Option::Some(self.iter());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T: PartialEq, const SZ: usize> crate::_Keyword<T> for &[T; SZ] {
|
||||
fn startComparation(&self, expectedLen: usize) -> Option<impl crate::_KeywordComparatorIterator<T>> {
|
||||
fn startComparation(
|
||||
&self,
|
||||
expectedLen: usize,
|
||||
) -> Option<impl crate::_KeywordComparatorIterator<T>> {
|
||||
if (self.len() != expectedLen) {
|
||||
return Option::None;
|
||||
}
|
||||
|
||||
return Option::Some(_ArrayIteratorImpl { orig: self.iter() });
|
||||
return Option::Some(self.iter());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
mod _keyword_impls;
|
||||
|
||||
pub trait Predicate<C> {
|
||||
fn check(&mut self, chr: &C) -> bool;
|
||||
fn check(&mut self, chr: C) -> bool;
|
||||
}
|
||||
|
||||
impl<C> Predicate<C> for fn(&C) -> bool {
|
||||
fn check(&mut self, chr: &C) -> bool {
|
||||
impl<C> Predicate<C> for fn(C) -> bool {
|
||||
fn check(&mut self, chr: C) -> bool {
|
||||
return self(chr);
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ impl<C> Predicate<C> for fn(&C) -> bool {
|
||||
pub trait Pos {}
|
||||
|
||||
pub trait _KeywordComparatorIterator<C> {
|
||||
fn consume(&mut self, c: &C) -> bool;
|
||||
fn consume(&mut self, c: C) -> bool;
|
||||
}
|
||||
|
||||
pub trait _Keyword<C> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user