Enum actix_form_data::Field
source · [−]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>)
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
Implementations
sourceimpl<T, E> Field<T, E>
impl<T, E> Field<T, E>
sourcepub fn file<F, Fut>(f: F) -> Self where
F: Fn(String, Mime, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = Result<T, E>> + 'static,
E: 'static,
pub fn file<F, Fut>(f: F) -> Self where
F: Fn(String, Mime, Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>) -> Fut + Send + Sync + 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>
}
}));
sourcepub fn bytes() -> Self
pub fn bytes() -> Self
Add a Bytes field to a form
Example
let form = Form::<(), Error>::new().field("text-field", Field::bytes());
sourcepub fn text() -> Self
pub fn text() -> Self
Add a Text field to a form
Example
let form = Form::<(), Error>::new().field("text-field", Field::text());
sourcepub fn int() -> Self
pub fn int() -> Self
Add an Int field to a form
Example
let form = Form::<(), Error>::new().field("int-field", Field::int());
sourcepub fn float() -> Self
pub 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more