Skip to main content

MultipartField

Struct MultipartField 

Source
pub struct MultipartField<'stream> { /* private fields */ }
Expand description

One part of a streamed multipart/form-data body.

Dropping a field without reading it to the end is allowed; the next MultipartStream::next_field call skips whatever is left.

Implementations§

Source§

impl MultipartField<'_>

Source

pub fn name(&self) -> &str

The part’s form field name.

Source

pub fn file_name(&self) -> Option<&str>

The part’s declared file name, when it has one.

Source

pub fn content_type(&self) -> Option<&str>

The part’s declared media type, when it has one.

Source

pub async fn next_chunk(&mut self) -> Result<Option<&[u8]>, MultipartError>

Pulls the next run of this part’s data.

The slice borrows the reader’s buffer and is valid until the next call, so nothing is copied on the way to the handler. Returns None once the part’s closing delimiter has been reached.

§Errors

Returns MultipartError when the document ends before its closing delimiter or when the transport fails.

Source

pub async fn collect(self, limit: usize) -> Result<Vec<u8>, MultipartError>

Deliberately buffers the rest of this part, with an explicit limit.

§Errors

Returns MultipartError::TooLarge when the part is longer than limit, or the reader failure that stopped it.

Source

pub async fn text(self, limit: usize) -> Result<String, MultipartError>

Deliberately buffers the rest of this part as text.

§Errors

Returns MultipartError::TooLarge when the part is longer than limit, MultipartError::Malformed when it is not UTF-8, or the reader failure that stopped it.

Source

pub async fn into_upload( self, limit: usize, ) -> Result<UploadFile, MultipartError>

Deliberately buffers the rest of this part as an UploadFile.

This is the bridge to the buffered API: an operation that wants the bytes after all gets the same value the File<UploadFile> extractor would have produced, having chosen the limit itself.

§Errors

Returns MultipartError::TooLarge when the part is longer than limit, or the reader failure that stopped it.

Trait Implementations§

Source§

impl<'stream> Debug for MultipartField<'stream>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'stream> !RefUnwindSafe for MultipartField<'stream>

§

impl<'stream> !Send for MultipartField<'stream>

§

impl<'stream> !Sync for MultipartField<'stream>

§

impl<'stream> !UnwindSafe for MultipartField<'stream>

§

impl<'stream> Freeze for MultipartField<'stream>

§

impl<'stream> Unpin for MultipartField<'stream>

§

impl<'stream> UnsafeUnpin for MultipartField<'stream>

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> BackgroundExt for T

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> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.