pub struct Parser<'b, const LINE: usize = 512, const MAX_HEADERS: usize = 16> { /* private fields */ }Expand description
Streaming, zero-copy multipart/form-data parser.
LINE is the size of the only buffer the parser owns: a part header line
(including its CRLF) must fit into it. MAX_HEADERS bounds the number of
header lines per part and costs no memory.
size_of::<Parser<LINE, _>>() == LINE + 5 * size_of::<usize>() (asserted by a
test): the boundary slice, the line length, the header counter and the state.
Implementations§
Source§impl<'b, const LINE: usize, const MAX_HEADERS: usize> Parser<'b, LINE, MAX_HEADERS>
impl<'b, const LINE: usize, const MAX_HEADERS: usize> Parser<'b, LINE, MAX_HEADERS>
Sourcepub fn new(boundary: &'b [u8]) -> Result<Self, Error>
pub fn new(boundary: &'b [u8]) -> Result<Self, Error>
Creates a parser for boundary (rule 1), which is borrowed, not copied.
§Errors
Error::Boundary if boundary is not 1–70 RFC 2046 bchars ending in a
non-space byte.
Sourcepub fn from_content_type(content_type: &'b [u8]) -> Result<Self, Error>
pub fn from_content_type(content_type: &'b [u8]) -> Result<Self, Error>
Creates a parser from a Content-Type header value such as
multipart/form-data; boundary=----x (rule 1). The boundary is borrowed
from content_type, quoted or unquoted.
§Errors
Error::Boundary if the value is not a multipart/* media type with a
valid boundary parameter.
Sourcepub const fn min_buffer(&self) -> usize
pub const fn min_buffer(&self) -> usize
The smallest input.len() that guarantees progress on every call
(boundary.len() + MAX_PADDING + 6, see DESIGN.md §9).
Sourcepub const fn is_finished(&self) -> bool
pub const fn is_finished(&self) -> bool
true once Finished has been returned.
Sourcepub fn parse<'i>(
&mut self,
input: &'i [u8],
eof: bool,
) -> Result<(usize, Option<Event<'i, '_>>), Error>
pub fn parse<'i>( &mut self, input: &'i [u8], eof: bool, ) -> Result<(usize, Option<Event<'i, '_>>), Error>
Consumes a prefix of input and yields at most one event.
The parser may consume fewer bytes than given (a possible delimiter prefix
at the end is held back): drop the first consumed bytes, append new ones
and call again. eof = true means no more input will follow.
Progress guarantee: if input.len() >= self.min_buffer() or eof, every
call consumes ≥ 1 byte, returns an event, or returns an error. After an
error every call returns the same error; after Finished every call
returns (input.len(), Some(Finished)).
§Errors
See Error; the parser is unusable afterwards.