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

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.

Create a Self from request parts asynchronously.

Create a Self from request head asynchronously. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

Performs the conversion.

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