Enum actix_form_data::Field[][src]

pub enum Field<T, E> {
    Array(Array<T, E>),
    Map(Map<T, E>),
    File(Arc<dyn Fn(String, Mime, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Pin<Box<dyn Future<Output = Result<T, E>>>> + Send + Sync>),
    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>)

Tuple Fields

0: Array<T, E>

Map(Map<T, E>)

Tuple Fields

0: Map<T, E>

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

Tuple Fields

0: Arc<dyn Fn(String, Mime, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Pin<Box<dyn Future<Output = Result<T, E>>>> + Send + Sync>

Bytes

Int

Float

Text

Implementations

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>
    }
}));

Add a Bytes field to a form

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

Add a Text field to a form

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

Add an Int field to a form

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

Add a Float field to a form

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

Add an Array to a form

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more