Struct saphir::multipart::Field

source ·
pub struct Field<'f> { /* private fields */ }
Available on crate feature multipart only.
Expand description

Represent a form-data field Only the data needed to construct the field will be read into memory

Implementations§

source§

impl<'f> Field<'f>

source

pub fn name(&self) -> &str

Returns the name param of the Content-Disposition header.

Currently return "" if the name is missing.

This will return an Option<*str> in saphir 4.0.0

source

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

Returns the optional filename param of the Content-Disposition header

source

pub fn content_type(&self) -> &Mime

Returns the optional Content-Type Mime and is defaulted to text/plain as specified by the spec

source

pub async fn as_raw(&mut self) -> Result<Vec<u8>, MultipartError>

👎Deprecated since 3.1.0: Use to_raw() instead.

Deprecated; Use to_raw() instead.

Loads the entire field into memory and returns it as raw bytes

This will be removed in saphir 4.0.0

source

pub async fn to_raw(self) -> Result<Vec<u8>, MultipartError>

Loads the entire field into memory and returns it as raw bytes

source

pub async fn as_text(&mut self) -> Result<String, MultipartError>

👎Deprecated since 3.1.0: use to_text() instead

Deprecated; Use to_raw() instead.

Loads the entire field into memory and returns it as plain text

This will be removed in saphir 4.0.0

source

pub async fn to_text(self) -> Result<String, MultipartError>

Loads the entire field into memory and returns it as plain text

source

pub async fn as_json<T>(&mut self) -> Result<Option<T>, MultipartError>where T: for<'a> Deserialize<'a>,

👎Deprecated since 3.1.0: use to_json() instead
Available on crate feature json only.

Deprecated; Use to_raw() instead.

Loads the entire field into memory and parses it as JSON data IF the content-type is application/json.

Return Ok(None) if the content-type was incorrect.

This will be removed in saphir 4.0.0

source

pub async fn to_json<T>(self) -> Result<Option<T>, MultipartError>where T: for<'a> Deserialize<'a>,

👎Deprecated since 3.1.0: use to_json() instead
Available on crate feature json only.

Loads the entire field into memory and parses it as JSON data IF the content-type is application/json.

Return Ok(None) if the content-type was incorrect.

source

pub async fn as_form<T>(&mut self) -> Result<Option<T>, MultipartError>where T: for<'a> Deserialize<'a>,

👎Deprecated since 3.1.0: use to_form() instead
Available on crate feature form only.

Deprecated; Use to_raw() instead.

Loads the entire field into memory and parses it as Form urlencoded data IF the content-type is application/x-www-form-urlencoded.

Return Ok(None) if the content-type was incorrect.

This will be removed in saphir 4.0.0

source

pub async fn to_form<T>(self) -> Result<Option<T>, MultipartError>where T: for<'a> Deserialize<'a>,

Available on crate feature form only.

Loads the entire field into memory and parses it as Form urlencoded data IF the content-type is application/x-www-form-urlencoded.

Return Ok(None) if the content-type was incorrect.

source

pub async fn save<P: AsRef<Path>>( &mut self, path: P ) -> Result<usize, MultipartError>

Saves the field into a file on disk.

This function will consume the field in saphir 4.0.0

Trait Implementations§

source§

impl Debug for Field<'_>

source§

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

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

impl<'f> From<Field<'f>> for Field<'f>

source§

fn from(raw: RawField<'f>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'f> !RefUnwindSafe for Field<'f>

§

impl<'f> Send for Field<'f>

§

impl<'f> Sync for Field<'f>

§

impl<'f> Unpin for Field<'f>

§

impl<'f> !UnwindSafe for Field<'f>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · 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