pub struct Validated<T>(/* private fields */);Expand description
A payload T that has been deserialized and validated.
Construction is possible only through from_body or
from_query (plus assume_valid
for test fixtures). All other callers receive a T provably free of
constraint violations.
Implementations§
Source§impl<T> Validated<T>
impl<T> Validated<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the wrapper, returning the validated inner value.
Sourcepub fn assume_valid(v: T) -> Self
pub fn assume_valid(v: T) -> Self
Construct without validation – use only in unit-test fixtures where the value is already known good. Never call in handler code.
Source§impl<T: DeserializeOwned + Validate> Validated<T>
impl<T: DeserializeOwned + Validate> Validated<T>
Sourcepub fn from_body(ctx: &RequestContext) -> Result<Self, HttpException>
pub fn from_body(ctx: &RequestContext) -> Result<Self, HttpException>
Deserialize T from the JSON request body, then run T::validate().
Returns Err(HttpException) on either step, converting automatically
into the RFC 7807 problem shape:
| Failure | Status | type field |
|---|---|---|
| Malformed JSON | 400 | bad-request |
| Constraint violated | 422 | validation |
Sourcepub fn from_query(ctx: &RequestContext) -> Result<Self, HttpException>
pub fn from_query(ctx: &RequestContext) -> Result<Self, HttpException>
Deserialize T from the URL query string, then validate.
Same error shape as from_body.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Validated<T>where
T: Freeze,
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> UnsafeUnpin for Validated<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Validated<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.impl<T> Formattable for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request