pub struct Form<T>(pub T);
Expand description
Wrapper used to create Form Http Response
s,
as well as to extract Form from Http Request
bodies.
§Examples
§Creating a Form Response
use serde::Serialize;
use rama_http_types::{
IntoResponse,
response::Form
};
#[derive(Serialize)]
struct Payload {
name: String,
age: i32,
is_student: bool
}
async fn handler() -> impl IntoResponse {
Form(Payload {
name: "john".to_string(),
age: 30,
is_student: false
})
}
§Extracting Form from a Request
use rama_http_types::response::Form;
#[derive(Debug, serde::Deserialize)]
struct Input {
name: String,
age: u8,
alive: Option<bool>,
}
async fn handler(Form(input): Form<Input>) {
if !input.alive.unwrap_or_default() {
bury(&input.name);
}
}
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<T> FromRequest for Form<T>
impl<T> FromRequest for Form<T>
Source§impl<T> IntoResponse for Form<T>where
T: Serialize,
impl<T> IntoResponse for Form<T>where
T: Serialize,
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Create a response.
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>where
T: Send,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<State, R> IntoEndpointService<State, ()> for R
impl<State, R> IntoEndpointService<State, ()> for R
Source§fn into_endpoint_service(
self,
) -> impl Service<State, Request<Body>, Response = Response<Body>, Error = Infallible>
fn into_endpoint_service( self, ) -> impl Service<State, Request<Body>, Response = Response<Body>, Error = Infallible>
convert the type into a
rama_core::Service
.