pub struct ZRedact<T>where
T: VldSchema,{ /* private fields */ }poem-openapi only.Expand description
Keep an inner schema’s input out of its errors (passwords, tokens,
personal data). Created via VldSchema::redact().
Every issue the inner schema reports — nested ones in an object or array
included — keeps its path, code and message, but its received
becomes REDACTED ("[redacted]"), so neither Display, Debug,
a serialized VldError nor an HTTP error body echoes the value.
Built-in messages never quote the input; a custom message that does (a
refinement or transform error formatting the value) has each input
string of 4+ characters in it replaced by the marker too.
Redact the outermost schema whose issues may carry the value: a check of
an enclosing schema (array(..).unique(), a union with no matching
variant) reports the value it saw as received, outside a redacted
element — redact the array / union itself.
use vld::prelude::*;
let login = vld::object()
.field("user", vld::string().min(1))
.field("password", vld::string().min(12).redact());
let err = login.parse(r#"{"user": "ada", "password": "hunter2"}"#).unwrap_err();
assert_eq!(err.issues[0].received, Some(serde_json::json!("[redacted]")));
assert!(!err.to_string().contains("hunter2"));Implementations§
Trait Implementations§
Source§impl<S> CollectNestedSchemas for ZRedact<S>where
S: VldSchema + CollectNestedSchemas,
impl<S> CollectNestedSchemas for ZRedact<S>where
S: VldSchema + CollectNestedSchemas,
Source§impl<S> JsonSchema for ZRedact<S>where
S: VldSchema + JsonSchema,
impl<S> JsonSchema for ZRedact<S>where
S: VldSchema + JsonSchema,
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
Source§fn is_required(&self) -> bool
fn is_required(&self) -> bool
required array. Read moreSource§impl<T> VldSchema for ZRedact<T>where
T: VldSchema,
impl<T> VldSchema for ZRedact<T>where
T: VldSchema,
Source§type Output = <T as VldSchema>::Output
type Output = <T as VldSchema>::Output
Source§fn parse_value(
&self,
value: &Value,
) -> Result<<T as VldSchema>::Output, VldError>
fn parse_value( &self, value: &Value, ) -> Result<<T as VldSchema>::Output, VldError>
serde_json::Value.Source§fn parse_missing(&self) -> Result<<T as VldSchema>::Output, VldError>
fn parse_missing(&self) -> Result<<T as VldSchema>::Output, VldError>
Source§fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
serde_json::Value, etc.)Source§fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
Source§fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
Source§fn optional(self) -> ZOptional<Self>
fn optional(self) -> ZOptional<Self>
None.Source§fn with_default(self, value: Self::Output) -> ZDefault<Self>
fn with_default(self, value: Self::Output) -> ZDefault<Self>
Source§fn blank_as(self, value: Self::Output) -> ZDefault<Self>
fn blank_as(self, value: Self::Output) -> ZDefault<Self>
with_default, and a blank string (empty or
whitespace only) also becomes value: legacy stores that write ""
or null for “unset”. Read moreSource§fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
Source§fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
rule with a custom error message.Source§fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
Err becomes a
validation issue (Custom { code: "transform" }, message = the error). Read moreSource§fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
Source§fn catch(self, fallback: Self::Output) -> ZCatch<Self>
fn catch(self, fallback: Self::Output) -> ZCatch<Self>
Source§fn pipe<S>(self, next: S) -> ZPipe<Self, S>
fn pipe<S>(self, next: S) -> ZPipe<Self, S>
Source§fn describe(self, description: &str) -> ZDescribe<Self>
fn describe(self, description: &str) -> ZDescribe<Self>
Source§fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
Source§fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
Either<Self::Output, B::Output>.Source§fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
Auto Trait Implementations§
impl<T> Forget for ZRedact<T>
impl<T> Freeze for ZRedact<T>where
T: Freeze,
impl<T> Move for ZRedact<T>
impl<T> RefUnwindSafe for ZRedact<T>where
T: RefUnwindSafe,
impl<T> Send for ZRedact<T>where
T: Send,
impl<T> Sync for ZRedact<T>where
T: Sync,
impl<T> Unpin for ZRedact<T>where
T: Unpin,
impl<T> UnsafeUnpin for ZRedact<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ZRedact<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
Source§impl<T> DynSchema for T
impl<T> DynSchema for T
Source§fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
value and return the output serialized back to JSON.Source§fn dyn_parse_missing(&self) -> Result<Value, VldError>
fn dyn_parse_missing(&self) -> Result<Value, VldError>
VldSchema::parse_missing of the erased schema.Source§fn dyn_json_schema(&self) -> Value
fn dyn_json_schema(&self) -> Value
openapi only.Source§fn dyn_is_required(&self) -> bool
fn dyn_is_required(&self) -> bool
openapi only.required array.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more