# Stateless vs Statefull parsing
When designing parsing API, there is a couple options which it can choose:
- stateless vs statefull parsing
- accept raw bytes vs buffered io
- copy vs no-copy
Each options affect in terms of flexibility, portability, ease of use, memory
usage, and performance.
And even better, if we can make it progressive.
# HTTP
HTTP contains a small headline, collection of headers, and body stream.
Parser can just focus on headline and headers, since body should be handled
differently by the caller.
## Stateless, raw bytes, no-copy parsing
```rust
struct ParseResult<'b> {
method: &'b str,
path: &'b str,
version: &'b str,
header_len: usize,
buf_len: usize,
}
fn parse<'b>(buf: &'b [u8], headers: &[Header<'b>]) -> ParseResult<'b> {
// ..
}
```
This API thrives in all metrics but one, it needs to retry when buffer is not
sufficient.
It can also be progressively added using buffered io.
```rust
fn parse_io<IO>(mut io: IO, cx: &mut Context) -> Poll<io::Result<ParseResult>> {
match parse(io.chunk())? {
Some(result) => {
io.consume(result.buf_len);
Poll::Ready(Ok(result))
},
None => {
ready!(io.poll_read_fill(cx)?);
parse_io(io, cx)
},
}
}
```