Struct rocket_validation::Validated
source · [−]pub struct Validated<T>(pub T);
Tuple Fields
0: T
Implementations
Trait Implementations
sourceimpl<'r, D: Validate + Deserialize<'r>> FromData<'r> for Validated<Json<D>>
impl<'r, D: Validate + Deserialize<'r>> FromData<'r> for Validated<Json<D>>
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])
}
type Error = Result<ValidationErrors, Error<'r>>
type Error = Result<ValidationErrors, Error<'r>>
The associated error to be returned when the guard fails.
sourcefn from_data<'life0, 'async_trait>(
req: &'r Request<'life0>,
data: Data<'r>
) -> Pin<Box<dyn Future<Output = DataOutcome<'r, Self>> + Send + 'async_trait>> where
'r: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn from_data<'life0, 'async_trait>(
req: &'r Request<'life0>,
data: Data<'r>
) -> Pin<Box<dyn Future<Output = DataOutcome<'r, Self>> + Send + 'async_trait>> where
'r: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Asynchronously validates, parses, and converts an instance of Self
from the incoming request body data. Read more
sourceimpl<'r, T: Validate + FromForm<'r>> FromForm<'r> for Validated<T>
impl<'r, T: Validate + FromForm<'r>> FromForm<'r> for Validated<T>
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])
}
sourcefn push_value(ctxt: &mut Self::Context, field: ValueField<'r>)
fn push_value(ctxt: &mut Self::Context, field: ValueField<'r>)
Processes the value field field
.
sourcefn push_data<'life0, 'life1, 'async_trait>(
ctxt: &'life0 mut Self::Context,
field: DataField<'r, 'life1>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'r: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn push_data<'life0, 'life1, 'async_trait>(
ctxt: &'life0 mut Self::Context,
field: DataField<'r, 'life1>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'r: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Processes the data field field
.
sourcefn push_error(_ctxt: &mut Self::Context, _error: Error<'r>)
fn push_error(_ctxt: &mut Self::Context, _error: Error<'r>)
Processes the external form or field error _error
. Read more
sourceimpl<'r, D: Validate + FromRequest<'r>> FromRequest<'r> for Validated<D>
impl<'r, D: Validate + FromRequest<'r>> FromRequest<'r> for Validated<D>
Implementation of Validated
for FromRequest
implementing Validate
Anything you implement FromRequest
for as well as Validate
type Error = Result<ValidationErrors, D::Error>
type Error = Result<ValidationErrors, D::Error>
The associated error to be returned if derivation fails.
Auto Trait Implementations
impl<T> RefUnwindSafe for Validated<T> where
T: RefUnwindSafe,
impl<T> Send for Validated<T> where
T: Send,
impl<T> Sync for Validated<T> where
T: Sync,
impl<T> Unpin for Validated<T> where
T: Unpin,
impl<T> UnwindSafe for Validated<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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> 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>
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
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