Struct routerify_multipart::Multipart[][src]

pub struct Multipart<'r> { /* fields omitted */ }
Expand description

Represents the implementation of multipart/form-data formatted data.

This will parse the source stream into Field instances via next_field().

Field Exclusivity

A Field represents a raw, self-decoding stream into multipart data. As such, only one Field from a given Multipart instance may be live at once. That is, a Field emitted by next_field() must be dropped before calling next_field() again. Failure to do so will result in an error.

use std::convert::Infallible;

use bytes::Bytes;
use futures_util::stream::once;
use multer::Multipart;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; \
    name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";

let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
let mut multipart = Multipart::new(stream, "X-BOUNDARY");

let field1 = multipart.next_field().await;
let field2 = multipart.next_field().await;

assert!(field2.is_err());

Examples

use std::convert::Infallible;

use bytes::Bytes;
use futures_util::stream::once;
use multer::Multipart;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; \
    name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";

let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
let mut multipart = Multipart::new(stream, "X-BOUNDARY");

while let Some(field) = multipart.next_field().await.unwrap() {
    println!("Field: {:?}", field.text().await)
}

Implementations

impl<'r> Multipart<'r>[src]

pub fn new<S, O, E, B>(stream: S, boundary: B) -> Multipart<'r> where
    E: Into<Box<dyn Error + 'static + Sync + Send, Global>> + 'r,
    B: Into<String>,
    S: Stream<Item = Result<O, E>> + Send + 'r,
    O: Into<Bytes> + 'static, 
[src]

Construct a new Multipart instance with the given Bytes stream and the boundary.

pub fn with_constraints<S, O, E, B>(
    stream: S,
    boundary: B,
    constraints: Constraints
) -> Multipart<'r> where
    E: Into<Box<dyn Error + 'static + Sync + Send, Global>> + 'r,
    B: Into<String>,
    S: Stream<Item = Result<O, E>> + Send + 'r,
    O: Into<Bytes> + 'static, 
[src]

Construct a new Multipart instance with the given Bytes stream and the boundary.

pub async fn next_field(&'_ mut self) -> Result<Option<Field<'r>>, Error>[src]

Yields the next Field if available.

Any previous Field returned by this method must be dropped before calling this method or Multipart::next_field_with_idx() again. See field-exclusivity for details.

pub async fn next_field_with_idx(
    &'_ mut self
) -> Result<Option<(usize, Field<'r>)>, Error>
[src]

Yields the next Field with their positioning index as a tuple (usize, Field).

Any previous Field returned by this method must be dropped before calling this method or Multipart::next_field() again. See field-exclusivity for details.

Examples

use std::convert::Infallible;

use bytes::Bytes;
use futures_util::stream::once;
use multer::Multipart;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; \
    name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";

let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
let mut multipart = Multipart::new(stream, "X-BOUNDARY");

while let Some((idx, field)) = multipart.next_field_with_idx().await.unwrap() {
    println!("Index: {:?}, Content: {:?}", idx, field.text().await)
}

Trait Implementations

impl<'r> Debug for Multipart<'r>[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'r> !RefUnwindSafe for Multipart<'r>

impl<'r> Send for Multipart<'r>

impl<'r> Sync for Multipart<'r>

impl<'r> Unpin for Multipart<'r>

impl<'r> !UnwindSafe for Multipart<'r>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

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

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.