markdown_stream/parser.rs
1//! The streaming parser contract.
2
3use crate::event::Event;
4
5/// An incremental, chunk-safe Markdown parser.
6///
7/// Feed bytes with [`write`](Parser::write) and drain the returned events; call
8/// [`flush`](Parser::flush) at end of input to close any open blocks. The emitted event stream is
9/// **independent of how the input is split** across `write` calls (split-equivalence) — the single
10/// most important invariant of this library.
11pub trait Parser {
12 /// Feed a chunk of input. Returns any events that became complete as a result. A chunk may end
13 /// mid-line; the parser buffers the remainder until the next `write`/`flush`.
14 fn write(&mut self, chunk: &[u8]) -> Vec<Event>;
15
16 /// Signal end of input: process any buffered partial line and emit closing events for every
17 /// still-open block (ending with `ExitBlock(Document)`).
18 fn flush(&mut self) -> Vec<Event>;
19
20 /// Clear all state so the parser can be reused for a new document.
21 fn reset(&mut self);
22}