The field type represents a field in the form-data that is allowed to be parsed.
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.
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
let form = Form::new().field("text-field", Field::text());
Add an Int field to a form
let form = Form::new().field("int-field", Field::int());
Add a Float field to a form
let form = Form::new().field("float-field", Field::float());
Add a Bytes field to a form
let form = Form::new().field("bytes-field", Field::bytes());
Add an Array to a form
let form = Form::new()
.field(
"array-field",
Field::array(Field::text())
);
Add a Map to a form
let form = Form::new()
.field(
"map-field",
Field::map()
.field("sub-field", Field::text())
.field("sub-field-two", Field::text())
.finalize()
);
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more