1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::fmt;
use std::io::{self, BufRead};
use std::result;
#[derive(Debug, PartialEq, Eq)]
pub enum BodyParseOutput {
Completed(usize),
Partial(usize),
}
#[derive(Debug)]
pub enum BodyParseError {
ReadError(io::Error),
}
impl fmt::Display for BodyParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl From<BodyParseError> for io::Error {
fn from(err: BodyParseError) -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
}
pub trait BodyParser {
fn parse<R: BufRead>(
&mut self,
r: &mut R,
body_buf: &mut Vec<u8>,
) -> result::Result<BodyParseOutput, BodyParseError>;
}