pub struct Validated<T>(pub T);

Tuple Fields

0: T

Implementations

Impl to get type T of Json

Impl to get type T

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Implementation of Validated for Json An example with Json

use rocket::serde::{json::Json, Deserialize, Serialize};
use rocket_validation::{Validate, Validated};
  
#[derive(Debug, Deserialize, Serialize, Validate)]
#[serde(crate = "rocket::serde")]
pub struct HelloData {
    #[validate(length(min = 1))]
    name: String,
    #[validate(range(min = 0, max = 100))]
    age: u8,
}
#[post("/hello", format = "application/json", data = "<data>")]
fn validated_hello(data: Validated<Json<HelloData>>) -> Json<HelloData> {
    Json(data.into_deep_inner())
}
  
#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", routes![validated_hello])
        .register("/", catchers![rocket_validation::validation_catcher])
}

The associated error to be returned when the guard fails.

Asynchronously validates, parses, and converts an instance of Self from the incoming request body data. Read more

Implementation of Validated for FromForm

An example validating a query struct

use rocket::serde::{json::Json, Deserialize, Serialize};
use rocket_validation::{Validate, Validated};
  
#[derive(Debug, Deserialize, Serialize, Validate, FromForm)]
#[serde(crate = "rocket::serde")]
pub struct HelloData {
    #[validate(length(min = 1))]
    name: String,
    #[validate(range(min = 0, max = 100))]
    age: u8,
}
#[get("/validated-hello?<params..>", format = "application/json")]
fn validated_hello(params: Validated<HelloData>) -> Json<HelloData> {
    Json(params.into_inner())
}
  
#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", routes![validated_hello])
        .register("/", catchers![rocket_validation::validation_catcher])
}

The form guard’s parsing context.

Initializes and returns the parsing context for Self.

Processes the value field field.

Processes the data field field.

Finalizes parsing. Returns the parsed value when successful or collection of Errors otherwise. Read more

Processes the external form or field error _error. Read more

Returns a default value, if any, to use when a value is desired and parsing fails. Read more

Implementation of Validated for FromRequest implementing Validate Anything you implement FromRequest for as well as Validate

The associated error to be returned if derivation fails.

Derives an instance of Self from the incoming request metadata. 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

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.

Converts self into a collection.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. 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