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.

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

Unwraps into inner T value.

Trait Implementations

Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more

See here for example of usage as an extractor.

The associated error which can be returned.
Future that resolves to a Self. Read more
Create a Self from request parts asynchronously.
Create a Self from request head asynchronously. Read more

Auto Trait Implementations

Blanket Implementations

A guard object containing the value and keeping it alive. Read more
The loading method. Read more
Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
The equivalent of Access::load.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Type of resource’s path returned in resource_path.
Should always be Self
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
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