recognize_slice/
recognize_slice.rs1use elyze::errors::ParseResult;
2use elyze::matcher::Match;
3use elyze::recognizer::recognize_slice;
4use elyze::scanner::Scanner;
5
6struct Hello;
8
9impl Match<u8> for Hello {
11 fn is_matching(&self, data: &[u8]) -> (bool, usize) {
12 let pattern = b"hello";
14 (&data[..pattern.len()] == pattern, pattern.len())
16 }
17
18 fn size(&self) -> usize {
19 5
20 }
21}
22
23fn main() -> ParseResult<()> {
24 let mut scanner = Scanner::new(b"hello world");
25 let hello_string = recognize_slice(Hello, &mut scanner)?;
26
27 println!("found: {}", String::from_utf8_lossy(hello_string)); print!(
29 "remaining: {:?}",
30 String::from_utf8_lossy(scanner.remaining())
31 ); Ok(())
34}