Skip to main content

Part

Struct Part 

Source
pub struct Part<'a> { /* private fields */ }
Available on crate feature alloc only.
Expand description

One part of a buffered multipart body. Its data borrows the body.

Implementations§

Source§

impl<'a> Part<'a>

Source

pub const fn index(&self) -> u32

The part index, from 0, in body order.

§Examples
assert_eq!(mp.parts()[0].index(), 0);
Source

pub fn name(&self) -> &str

The field name, HTML escapes (%0A, %0D, %22) decoded.

§Examples
assert_eq!(mp.parts()[0].name(), "a\"b");
Source

pub const fn kind(&self) -> PartKind

Field or file.

§Examples
assert_eq!(mp.parts()[0].kind(), form_net::PartKind::File);
Source

pub const fn is_file(&self) -> bool

Whether this is a file part.

§Examples
assert!(!mp.parts()[0].is_file());
Source

pub fn filename(&self) -> Option<FileName<'_>>

The client’s file name, for file parts.

§Examples
assert_eq!(mp.parts()[0].filename().unwrap().raw(), b"me.png");
Source

pub fn content_type(&self) -> Option<ContentType<'a>>

The declared Content-Type: a hint, never trusted.

§Examples
assert!(mp.parts()[0].content_type().unwrap().is("image", "png"));
Source

pub const fn bytes(&self) -> &'a [u8] ⓘ

The part’s data, borrowed from the body.

§Examples
assert_eq!(mp.parts()[0].bytes(), b"hello");
Source

pub fn text(&self) -> Result<&'a str, FormError>

The data as text. Text fields were checked at parse time, so this cannot fail for them; for file parts it checks UTF-8 now.

§Errors

Encoding { InvalidUtf8 }.

§Examples
assert_eq!(mp.parts()[0].text()?, "hello");
Source

pub const fn len(&self) -> usize

The data length.

§Examples
assert_eq!(mp.parts()[0].len(), 5);
Source

pub const fn is_empty(&self) -> bool

Whether the data is empty.

§Examples
assert!(mp.parts()[0].is_empty());

Trait Implementations§

Source§

impl Debug for Part<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Part<'a>

§

impl<'a> RefUnwindSafe for Part<'a>

§

impl<'a> Send for Part<'a>

§

impl<'a> Sync for Part<'a>

§

impl<'a> Unpin for Part<'a>

§

impl<'a> UnsafeUnpin for Part<'a>

§

impl<'a> UnwindSafe for Part<'a>

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.