source-stream-0.rs/src/_keyword_impls.rs

67 lines
1.8 KiB
Rust

use std::slice::Iter;
use std::str::Chars;
impl<'keyword> crate::KeywordComparatorIterator<'keyword, char> for Chars<'keyword> {
fn consume(&mut self, e: char) -> bool {
return self.next().is_some_and(|a| a == e);
}
}
impl crate::Keyword<char> for &str {
fn startComparation<'keyword>(
&'keyword self,
expectedLen: usize,
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
if (self.len() != expectedLen) {
return Option::None;
}
return Option::Some(self.chars());
}
}
impl crate::Keyword<char> for &String {
fn startComparation<'keyword>(
&'keyword self,
expectedLen: usize,
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
if (self.len() != expectedLen) {
return Option::None;
}
return Option::Some(self.chars());
}
}
impl<'keyword, C: PartialEq> crate::KeywordComparatorIterator<'keyword, C> for Iter<'keyword, C> {
fn consume(&mut self, e: C) -> bool {
return self.next().is_some_and(|a| a.eq(&e));
}
}
impl<C: PartialEq> crate::Keyword<C> for &[C] {
fn startComparation<'keyword>(
&'keyword self,
expectedLen: usize,
) -> Option<impl crate::KeywordComparatorIterator<'keyword, C>> {
if (self.len() != expectedLen) {
return Option::None;
}
return Option::Some(self.iter());
}
}
impl<C: PartialEq, const SZ: usize> crate::Keyword<C> for &[C; SZ] {
fn startComparation<'keyword>(
&'keyword self,
expectedLen: usize,
) -> Option<impl crate::KeywordComparatorIterator<'keyword, C>> {
if (self.len() != expectedLen) {
return Option::None;
}
return Option::Some(self.iter());
}
}