stap

stap (stateful parser) is a library of stateful parser for streaming input using async syntax.
When a input isn't enough for parsing, stap remembers the curent state and waits to more inputs and parses them when the input is supplied.
use futures::FutureExt;
use stap::{many1, Anchor, Cursor, Input, Parsing};
fn main() {
let mut input = Input::new(Cursor {
buf: Vec::<u8>::new(),
index: 0,
});
let mut parsing = Parsing::new(&mut input, |mut iref| {
async move {
let mut anchor = Anchor::new(&mut iref);
let num = many1(&mut anchor, |b| b.is_ascii_digit()).await?;
dbg!(&num);
let alpha = many1(&mut anchor, |b| b.is_ascii_alphabetic()).await?;
dbg!(&alpha);
anchor.forget();
Ok::<_, ()>((num, alpha))
}
.boxed_local()
});
assert!(!parsing.poll());
parsing.cursor_mut().buf.extend_from_slice(b"123a");
assert!(!parsing.poll());
parsing.cursor_mut().buf.extend_from_slice(b"bc;");
assert!(parsing.poll());
dbg!(parsing.into_result());
}