pub struct Form<T>(pub T)
where
T: for<'de> Deserialize<'de> + Send;
Expand description
Represented as form data
when post
as a application/x-www-form-urlencoded
, we can using this struct to inject data,
note: the struct must impl serde::Deserialize
and Send
§Example
#[derive(Deserialize, Debug)]
struct Params {
name: String,
zip: String,
}
pub async fn handle(Form(params) : Form<Params>) -> String {
format!("received params: {:?}", params)
}
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<T> FromRequest for Form<T>where
T: for<'de> Deserialize<'de> + Send,
Extracts form data from request body
impl<T> FromRequest for Form<T>where
T: for<'de> Deserialize<'de> + Send,
Extracts form data from request body
This implementation expects the request body to be URL-encoded form data
and deserializes it into the target type using serde_urlencoded
.
type Output<'r> = Form<T>
type Error = ParseError
async fn from_request<'r>( req: &'r RequestContext<'_, '_>, body: OptionReqBody, ) -> Result<Self::Output<'r>, Self::Error>
Auto Trait Implementations§
impl<T> Freeze for Form<T>where
T: Freeze,
impl<T> RefUnwindSafe for Form<T>where
T: RefUnwindSafe,
impl<T> Send for Form<T>
impl<T> Sync for Form<T>where
T: Sync,
impl<T> Unpin for Form<T>where
T: Unpin,
impl<T> UnwindSafe for Form<T>where
T: UnwindSafe,
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