Struct actix_web_lab::json::Json [−][src]
pub struct Json<T, const LIMIT: usize>(pub T);
Expand description
JSON extractor with const-generic payload size limit.
Json
is used to extract typed data from JSON request payloads.
Extractor
To extract typed data from a request body, the inner type T
must implement the
serde::Deserialize
trait.
Use the LIMIT
const generic parameter to control the payload size limit. The default limit
that is exported (DEFAULT_LIMIT
) is 2MiB.
When const generics defaults are supported (due for Rust 1.59) it will be possible to omit the default limit.
use actix_web::{post, App};
use actix_web_lab::json::{DEFAULT_LIMIT, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// Deserialize `Info` from request's body.
#[post("/")]
async fn index(info: Json<Info, DEFAULT_LIMIT>) -> String {
format!("Welcome {}!", info.username)
}
/// Deserialize payload with a higher 32MiB limit.
#[post("/big-payload")]
async fn big_payload(info: Json<Info, 33_554_432>) -> String {
format!("Welcome {}!", info.username)
}
Tuple Fields
0: T
Implementations
Unwrap into inner T
value.
Trait Implementations
See here for example of usage as an extractor.
type Future = JsonExtractFut<T, LIMIT>
type Future = JsonExtractFut<T, LIMIT>
Future that resolves to a Self.
Create a Self from request parts asynchronously.
Create a Self from request head asynchronously. Read more
Auto Trait Implementations
impl<T, const LIMIT: usize> RefUnwindSafe for Json<T, LIMIT> where
T: RefUnwindSafe,
impl<T, const LIMIT: usize> UnwindSafe for Json<T, LIMIT> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more