Enum form_data::Field[][src]

pub enum Field {
    Array(Array),
    File(Arc<FilenameGenerator>),
    Map(Map),
    Int,
    Float,
    Text,
    Bytes,
}

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

Variants

Methods

impl Field
[src]

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


struct Gen;

impl FilenameGenerator for Gen {
    fn next_filename(&self, _: &mime::Mime) -> Option<PathBuf> {
        Some(AsRef::<Path>::as_ref("path.png").to_owned())
    }
}

fn main() {
    let name_generator = Gen;
    let form = Form::new()
        .field("file-field", Field::file(name_generator));
}

Add a Text field to a form

Example

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

Add an Int field to a form

Example

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

Add a Float field to a form

Example

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

Add a Bytes field to a form

Example

let form = Form::new().field("bytes-field", Field::bytes());

Add an Array to a form

Example

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

Add a Map to a form

Example

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

Trait Implementations

impl Clone for Field
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Field
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Field

impl Sync for Field