Skip to main content

Part

Struct Part 

Source
pub struct Part<'m, S>
where S: Stream<Item = Result<Bytes, Error>> + Send + Unpin,
{ /* 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>
where S: Stream<Item = Result<Bytes, Error>> + Send + Unpin,

Source

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.

Source

pub fn poll_next_data( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<Bytes>, Error>>

Poll-based variant of Part::next_data.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<S> Debug for Part<'_, S>
where S: Stream<Item = Result<Bytes, Error>> + Send + Unpin,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'m, S> !UnwindSafe for Part<'m, S>

§

impl<'m, S> Freeze for Part<'m, S>
where &'m mut Multipart<S>: Freeze,

§

impl<'m, S> RefUnwindSafe for Part<'m, S>
where &'m mut Multipart<S>: RefUnwindSafe,

§

impl<'m, S> Send for Part<'m, S>
where &'m mut Multipart<S>: Send,

§

impl<'m, S> Sync for Part<'m, S>
where &'m mut Multipart<S>: Sync,

§

impl<'m, S> Unpin for Part<'m, S>
where &'m mut Multipart<S>: Unpin,

§

impl<'m, S> UnsafeUnpin for Part<'m, S>
where &'m mut Multipart<S>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.