pub struct ValidatedJson<T>(pub T);Expand description
Validated JSON body extractor
Parses the request body as JSON, deserializes into type T, and validates
using the Validate trait. Returns a 422 Unprocessable Entity error with
detailed field-level validation errors if validation fails.
§Example
ⓘ
use rustapi_rs::prelude::*;
use validator::Validate;
#[derive(Deserialize, Validate)]
struct CreateUser {
#[validate(email)]
email: String,
#[validate(length(min = 8))]
password: String,
}
async fn register(ValidatedJson(body): ValidatedJson<CreateUser>) -> impl IntoResponse {
// body is already validated!
// If email is invalid or password too short, a 422 error is returned automatically
}Tuple Fields§
§0: TImplementations§
Source§impl<T> ValidatedJson<T>
impl<T> ValidatedJson<T>
Sourcepub fn new(value: T) -> ValidatedJson<T>
pub fn new(value: T) -> ValidatedJson<T>
Create a new ValidatedJson wrapper
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Get the inner value
Trait Implementations§
Source§impl<T> Clone for ValidatedJson<T>where
T: Clone,
impl<T> Clone for ValidatedJson<T>where
T: Clone,
Source§fn clone(&self) -> ValidatedJson<T>
fn clone(&self) -> ValidatedJson<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for ValidatedJson<T>where
T: Debug,
impl<T> Debug for ValidatedJson<T>where
T: Debug,
Source§impl<T> Default for ValidatedJson<T>where
T: Default,
impl<T> Default for ValidatedJson<T>where
T: Default,
Source§fn default() -> ValidatedJson<T>
fn default() -> ValidatedJson<T>
Returns the “default value” for a type. Read more
Source§impl<T> Deref for ValidatedJson<T>
impl<T> Deref for ValidatedJson<T>
Source§impl<T> DerefMut for ValidatedJson<T>
impl<T> DerefMut for ValidatedJson<T>
Source§impl<T> From<T> for ValidatedJson<T>
impl<T> From<T> for ValidatedJson<T>
Source§fn from(value: T) -> ValidatedJson<T>
fn from(value: T) -> ValidatedJson<T>
Converts to this type from the input type.
Source§impl<T> FromRequest for ValidatedJson<T>
impl<T> FromRequest for ValidatedJson<T>
Source§async fn from_request(req: &mut Request) -> Result<ValidatedJson<T>, ApiError>
async fn from_request(req: &mut Request) -> Result<ValidatedJson<T>, ApiError>
Extract from the full request
Source§impl<T> IntoResponse for ValidatedJson<T>where
T: Serialize,
impl<T> IntoResponse for ValidatedJson<T>where
T: Serialize,
Source§impl<T> OperationModifier for ValidatedJson<T>where
T: for<'a> ToSchema<'a>,
impl<T> OperationModifier for ValidatedJson<T>where
T: for<'a> ToSchema<'a>,
Source§fn update_operation(op: &mut Operation)
fn update_operation(op: &mut Operation)
Update the operation
impl<T> Copy for ValidatedJson<T>where
T: Copy,
Auto Trait Implementations§
impl<T> Freeze for ValidatedJson<T>where
T: Freeze,
impl<T> RefUnwindSafe for ValidatedJson<T>where
T: RefUnwindSafe,
impl<T> Send for ValidatedJson<T>where
T: Send,
impl<T> Sync for ValidatedJson<T>where
T: Sync,
impl<T> Unpin for ValidatedJson<T>where
T: Unpin,
impl<T> UnwindSafe for ValidatedJson<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more