Skip to main content

MultipartFormData

Struct MultipartFormData 

Source
pub struct MultipartFormData;
Expand description

Parser for multipart/form-data bodies.

Decodes a body into its parts using the boundary declared by the request Content-Type header, without depending on any external multipart crate.

Implementations§

Source§

impl MultipartFormData

Implementation for MultipartFormData.

Source

pub fn get_boundary<C>(content_type: C) -> Option<String>
where C: AsRef<str>,

Reads the boundary parameter out of a multipart/form-data content type.

The parameter is matched case-insensitively and accepts both a quoted and a bare value, so the clients that emit boundary="abc" and the clients that emit boundary=abc are both accepted. A parameter that carries no = is skipped rather than aborting the scan.

§Arguments
  • C - The content type header value, which requires the AsRef<str> bound.
§Returns
  • Option<MultipartFormDataBoundary> - The declared boundary, or None when absent.
Source

pub fn is_form_data<C>(content_type: C) -> bool
where C: AsRef<str>,

Checks whether a content type declares a multipart/form-data body.

§Arguments
  • C - The content type header value, which requires the AsRef<str> bound.
§Returns
  • bool - Whether the content type is multipart/form-data.
Source

pub fn parse<B>(body: B, boundary: &str) -> Option<Vec<BodyPart>>
where B: AsRef<[u8]>,

Decodes every part of a multipart/form-data body.

A body that carries no declared boundary, a body whose final boundary is not the closing one, and a part that declares no name all yield None.

§Arguments
  • B - The raw request body, which requires the AsRef<[u8]> bound.
  • &str - The declared boundary, without its leading dash pair.
§Returns
  • Option<MultipartFormDataParts> - The decoded parts, or None when malformed.
Source

pub fn try_get_part<K>(parts: &[BodyPart], name: K) -> Option<&BodyPart>
where K: AsRef<str>,

Tries to get a part by its form field name.

§Arguments
  • &[BodyPart] - The decoded parts of the body.
  • K - The form field name, which requires the AsRef<str> bound.
§Returns
  • Option<&BodyPart> - The first part carrying that name, or None.
Source

pub fn try_get_part_text<K>(parts: &[BodyPart], name: K) -> Option<String>
where K: AsRef<str>,

Tries to get a plain text field by its form field name.

A part that uploads a file is skipped, so a file field never silently decodes as text.

§Arguments
  • &[BodyPart] - The decoded parts of the body.
  • K - The form field name, which requires the AsRef<str> bound.
§Returns
  • Option<BodyFormValue> - The field value, or None when absent or a file.
Source

pub fn parse_url_encoded<B>( body: B, ) -> HashMap<String, String, BuildHasherDefault<Hasher>>
where B: AsRef<[u8]>,

Decodes an application/x-www-form-urlencoded body into its fields.

§Arguments
  • B - The raw request body, which requires the AsRef<[u8]> bound.
§Returns
  • BodyForm - The decoded form fields.

Trait Implementations§

Source§

impl Clone for MultipartFormData

Source§

fn clone(&self) -> MultipartFormData

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MultipartFormData

Source§

impl Debug for MultipartFormData

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MultipartFormData

Source§

fn default() -> MultipartFormData

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MultipartFormData

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<MultipartFormData, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for MultipartFormData

Source§

impl PartialEq for MultipartFormData

Source§

fn eq(&self, other: &MultipartFormData) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for MultipartFormData

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MultipartFormData

Auto Trait Implementations§

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> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more