pub struct Toon<T>(pub T);Expand description
TOON body extractor and response type
This extractor parses TOON-formatted request bodies and deserializes them into the specified type. It can also be used as a response type to serialize data into TOON format.
§Request Extraction
Accepts request bodies with content types:
application/toontext/toon
§Example - Extractor
ⓘ
use rustapi_rs::prelude::*;
use rustapi_rs::toon::Toon;
#[derive(Deserialize)]
struct CreateUser {
name: String,
email: String,
}
async fn create_user(Toon(user): Toon<CreateUser>) -> impl IntoResponse {
// user is parsed from TOON format
Json(user)
}§Example - Response
ⓘ
use rustapi_rs::prelude::*;
use rustapi_rs::toon::Toon;
#[derive(Serialize)]
struct User {
id: u64,
name: String,
}
async fn get_user() -> Toon<User> {
Toon(User {
id: 1,
name: "Alice".to_string(),
})
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: DeserializeOwned + Send> FromRequest for Toon<T>
impl<T: DeserializeOwned + Send> FromRequest for Toon<T>
Source§async fn from_request(req: &mut Request) -> Result<Self>
async fn from_request(req: &mut Request) -> Result<Self>
Extract from the full request
Source§impl<T: Serialize> IntoResponse for Toon<T>
impl<T: Serialize> IntoResponse for Toon<T>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert self into a Response
Source§impl<T: Send> OperationModifier for Toon<T>
impl<T: Send> OperationModifier for Toon<T>
fn update_operation(op: &mut Operation)
Source§impl<T: Serialize> ResponseModifier for Toon<T>
impl<T: Serialize> ResponseModifier for Toon<T>
fn update_response(op: &mut Operation)
impl<T: Copy> Copy for Toon<T>
Auto Trait Implementations§
impl<T> Freeze for Toon<T>where
T: Freeze,
impl<T> RefUnwindSafe for Toon<T>where
T: RefUnwindSafe,
impl<T> Send for Toon<T>where
T: Send,
impl<T> Sync for Toon<T>where
T: Sync,
impl<T> Unpin for Toon<T>where
T: Unpin,
impl<T> UnwindSafe for Toon<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, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.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 more