pub struct Part<'m, S>{ /* private fields */ }Expand description
A single multipart part yielded by Multipart.
The part borrows the parser mutably. The returned headers and data borrow the parser’s internal buffer, so callers process each item before asking for the next one.
Implementations§
Source§impl<'m, S> Part<'m, S>
impl<'m, S> Part<'m, S>
Sourcepub fn poll_next_header(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Header<'_>>, Error>>
pub fn poll_next_header( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<Header<'_>>, Error>>
Poll-based variant of Part::next_header.
The two paths repeat the same poll_ensure_headers handshake by hand;
see the note in Part::next_header for why they cannot share it.
Sourcepub fn poll_next_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Bytes>, Error>>
pub fn poll_next_data( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<Bytes>, Error>>
Poll-based variant of Part::next_data.
Sourcepub async fn next_header(&mut self) -> Result<Option<Header<'_>>, Error>
pub async fn next_header(&mut self) -> Result<Option<Header<'_>>, Error>
Returns the next header of this part.
Headers are yielded one at a time and borrow the parser’s internal
buffer for the duration of the call. None marks the end of the
header block; the part is then positioned at the start of its data.
Parts carrying more than three header fields are accepted; fields beyond the first three are ignored, as RFC 7578 section 4.8 asks of a receiver.
§Errors
Returns an error when the header block is malformed, exceeds the configured buffer limit, or the underlying stream fails.
Sourcepub async fn next_data(&mut self) -> Result<Option<Bytes>, Error>
pub async fn next_data(&mut self) -> Result<Option<Bytes>, Error>
Returns the next data chunk of this part.
Entering the data phase discards headers that have not been yielded yet:
the header block is parsed if needed and the parser then moves past it.
Data chunks are passed through from the underlying stream whenever
possible. Every yielded chunk is non-empty: when the delimiter is
already at the front there is no data to hand out, and None marks the
end of this part’s data right away. The parser has then consumed the
delimiter and is positioned before the next part.
§Errors
Returns an error when the stream ends without a delimiter, the data is malformed, or the underlying stream fails.
Sourcepub fn take_data_stream(self) -> Result<PartDataStream<S>, Error>
pub fn take_data_stream(self) -> Result<PartDataStream<S>, Error>
Takes the remaining multipart stream, returning a self-contained
PartDataStream.
The header block must already have been parsed, which the first
completed Part::next_header call guarantees (a part without headers
returns None from it). Headers that have not been yielded yet are
discarded, exactly as when the data phase is entered through
Part::next_data. The returned stream yields this part’s data
and ends at the closing delimiter \r\n--boundary; it does not
interpret what follows. Convert it with
PartDataStream::into_final to validate the strict closing
trailer (the --boundary--\r\n form followed by end of stream).
§Errors
Returns Error::InvalidFormat when the header block has not been
parsed at all.