Skip to main content

Multipart

Struct Multipart 

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

The parts of a buffered multipart body, in body order.

Debug prints names, kinds, and lengths, never data.

Implementations§

Source§

impl<'a> Multipart<'a>

Source

pub fn parts(&self) -> &[Part<'a>]

Every part, in body order.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!(mp.parts().len(), 1);
Source

pub fn field(&self, name: &str) -> Option<&'a str>

The first text field named name.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!(mp.field("title"), Some("Holiday"));
assert_eq!(mp.field("other"), None);
Source

pub fn field_one(&self, name: &str) -> Result<Option<&'a str>, FormError>

The text field named name, refusing a name given twice.

§Errors

Extract { reason: Duplicate, field: None }.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert!(mp.field_one("a").is_err());
assert_eq!(mp.field_one("b")?, None);
Source

pub fn fields<'m>(&'m self, name: &'m str) -> impl Iterator<Item = &'a str> + 'm

Every text field named name, in body order.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!(mp.fields("t").collect::<Vec<_>>(), ["a", "b"]);
Source

pub fn file(&self, name: &str) -> Option<&Part<'a>>

The first file part named name.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!(mp.file("f").map(|p| p.bytes()), Some(&b"hi"[..]));
Source

pub fn files<'m>( &'m self, name: &'m str, ) -> impl Iterator<Item = &'m Part<'a>> + 'm

Every file part named name, in body order.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!(mp.files("f").count(), 2);
Source

pub fn len(&self) -> usize

The number of parts.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", b"--X--")?;
assert_eq!(mp.len(), 0);
Source

pub fn is_empty(&self) -> bool

Whether there are no parts.

§Examples
let mp = form_net::parse_multipart(b"multipart/form-data; boundary=X", b"--X--\r\n")?;
assert!(mp.is_empty());

Trait Implementations§

Source§

impl Debug for Multipart<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Multipart<'a>

§

impl<'a> RefUnwindSafe for Multipart<'a>

§

impl<'a> Send for Multipart<'a>

§

impl<'a> Sync for Multipart<'a>

§

impl<'a> Unpin for Multipart<'a>

§

impl<'a> UnsafeUnpin for Multipart<'a>

§

impl<'a> UnwindSafe for Multipart<'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.