Struct MultipartField

Source
pub struct MultipartField<S, E>
where S: Stream<Item = Result<Bytes, E>> + Unpin, E: Into<Box<dyn StdError + Send + Sync + 'static>>,
{ /* private fields */ }
Expand description

A single field of a MultipartStream which itself is a stream

This represents either an uploaded file, or a simple text value

Each field will have some headers and then a body. There are no assumptions made when parsing about what headers are present, but some of the helper methods here (such as content_type() & filename()) will return an error if they aren’t present. The body will be returned as an inner stream of bytes from the request, but up to the end of the field.

Fields are not concurrent against their parent multipart request. This is because multipart submissions are a single http request and we don’t support going backwards or skipping bytes. In other words you can’t read from multiple fields from the same request at the same time: you must wait for one field to finish being read before moving on.

Implementations§

Source§

impl<S, E> MultipartField<S, E>
where S: Stream<Item = Result<Bytes, E>> + Unpin, E: Into<Box<dyn StdError + Send + Sync + 'static>>,

Source

pub fn headers(&self) -> &HeaderMap<HeaderValue>

Return the headers for the field

You can use self.headers.get("my-header").and_then(|val| val.to_str().ok()) to get out the header if present

Source

pub fn content_type(&self) -> Result<&str, MultipartError>

Return the content type of the field (if present or error)

Source

pub fn filename(&self) -> Result<Cow<'_, str>, MultipartError>

Return the filename of the field (if present or error). The returned filename will be utf8 percent-decoded

Source

pub fn name(&self) -> Result<Cow<'_, str>, MultipartError>

Return the name of the field (if present or error). The returned name will be utf8 percent-decoded

Trait Implementations§

Source§

impl<S, E> Stream for MultipartField<S, E>
where S: Stream<Item = Result<Bytes, E>> + Unpin, E: Into<Box<dyn StdError + Send + Sync + 'static>>,

Source§

type Item = Result<Bytes, MultipartError>

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

§

impl<S, E> Freeze for MultipartField<S, E>

§

impl<S, E> RefUnwindSafe for MultipartField<S, E>

§

impl<S, E> Send for MultipartField<S, E>
where S: Send,

§

impl<S, E> Sync for MultipartField<S, E>
where S: Send,

§

impl<S, E> Unpin for MultipartField<S, E>

§

impl<S, E> UnwindSafe for MultipartField<S, E>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V