pub enum Field<T, E> {
    Array(Array<T, E>),
    Map(Map<T, E>),
    File(Box<dyn Fn(String, Option<Mime>, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Pin<Box<dyn Future<Output = Result<T, E>>>>>),
    Bytes,
    Int,
    Float,
    Text,
}
Expand description

The field type represents a field in the form-data that is allowed to be parsed.

Variants§

§

Array(Array<T, E>)

§

Map(Map<T, E>)

§

File(Box<dyn Fn(String, Option<Mime>, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Pin<Box<dyn Future<Output = Result<T, E>>>>>)

§

Bytes

§

Int

§

Float

§

Text

Implementations§

source§

impl<T, E> Field<T, E>

source

pub fn file<F, Fut>(f: F) -> Self
where F: Fn(String, Option<Mime>, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Fut + Clone + 'static, Fut: Future<Output = Result<T, E>> + 'static, E: 'static,

Add a File field with a name generator.

The name generator will be called for each file matching this field’s key. Keep in mind that each key/file pair will have it’s own name-generator, so sharing a name-generator between fields is up to the user.

Example
let (tx, rx) = channel(1);
let form = Form::new().field("file-field", Field::file(move |_, _, mut stream| {
    let mut tx = tx.clone();
    async move {
        while let Some(res) = stream.next().await {
            if let Ok(bytes) = res {
                if let Err(_) = tx.send(bytes).await {
                    break;
                }
            }
        }
        Ok(()) as Result<_, Error>
    }
}));
source

pub const fn bytes() -> Self

Add a Bytes field to a form

Example
let form = Form::<(), Error>::new().field("text-field", Field::bytes());
source

pub const fn text() -> Self

Add a Text field to a form

Example
let form = Form::<(), Error>::new().field("text-field", Field::text());
source

pub const fn int() -> Self

Add an Int field to a form

Example
let form = Form::<(), Error>::new().field("int-field", Field::int());
source

pub const fn float() -> Self

Add a Float field to a form

Example
let form = Form::<(), Error>::new().field("float-field", Field::float());
source

pub fn array(field: Field<T, E>) -> Self

Add an Array to a form

Example
let form = Form::<(), Error>::new()
    .field(
        "array-field",
        Field::array(Field::text())
    );
source

pub const fn map() -> Map<T, E>

Add a Map to a form

Example
let form = Form::<(), Error>::new()
    .field(
        "map-field",
        Field::map()
            .field("sub-field", Field::text())
            .field("sub-field-two", Field::text())
            .finalize()
    );

Trait Implementations§

source§

impl<T, E> Debug for Field<T, E>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, E> !RefUnwindSafe for Field<T, E>

§

impl<T, E> !Send for Field<T, E>

§

impl<T, E> !Sync for Field<T, E>

§

impl<T, E> Unpin for Field<T, E>

§

impl<T, E> !UnwindSafe for Field<T, E>

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

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