Struct actix_web_lab::extract::Json
source · [−]pub struct Json<T, const LIMIT: usize = DEFAULT_JSON_LIMIT>(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::extract::{DEFAULT_JSON_LIMIT, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// Deserialize `Info` from request's body.
#[post("/")]
async fn index(info: Json<Info>) -> String {
format!("Welcome {}!", info.username)
}
const LIMIT_32_MB: usize = 33_554_432;
/// Deserialize payload with a higher 32MiB limit.
#[post("/big-payload")]
async fn big_payload(info: Json<Info, LIMIT_32_MB>) -> String {
format!("Welcome {}!", info.username)
}
Tuple Fields
0: T
Implementations
sourceimpl<T, const LIMIT: usize> Json<T, LIMIT>
impl<T, const LIMIT: usize> Json<T, LIMIT>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap into inner T
value.
Trait Implementations
sourceimpl<T: DeserializeOwned, const LIMIT: usize> FromRequest for Json<T, LIMIT>
impl<T: DeserializeOwned, const LIMIT: usize> FromRequest for Json<T, LIMIT>
See here for example of usage as an extractor.
sourcefn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Create a Self
from request parts asynchronously.
sourcefn extract(req: &HttpRequest) -> Self::Future
fn extract(req: &HttpRequest) -> Self::Future
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> Send for Json<T, LIMIT>where
T: Send,
impl<T, const LIMIT: usize> Sync for Json<T, LIMIT>where
T: Sync,
impl<T, const LIMIT: usize> Unpin for Json<T, LIMIT>where
T: Unpin,
impl<T, const LIMIT: usize> UnwindSafe for Json<T, LIMIT>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
sourcefn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of Access::load
.
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, P> Resource for Twhere
T: DerefMut<Target = Path<P>>,
P: ResourcePath,
impl<T, P> Resource for Twhere
T: DerefMut<Target = Path<P>>,
P: ResourcePath,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
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