Enum actix_form_data::Field
source · 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>
impl<T, E> Field<T, E>
sourcepub fn file<F, Fut>(f: F) -> Self
pub fn file<F, Fut>(f: F) -> Self
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>
}
}));
sourcepub const fn bytes() -> Self
pub const fn bytes() -> Self
Add a Bytes field to a form
Example
let form = Form::<(), Error>::new().field("text-field", Field::bytes());
sourcepub const fn text() -> Self
pub const fn text() -> Self
Add a Text field to a form
Example
let form = Form::<(), Error>::new().field("text-field", Field::text());
sourcepub const fn int() -> Self
pub const fn int() -> Self
Add an Int field to a form
Example
let form = Form::<(), Error>::new().field("int-field", Field::int());
sourcepub const fn float() -> Self
pub const fn float() -> Self
Add a Float field to a form
Example
let form = Form::<(), Error>::new().field("float-field", Field::float());
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more