pub struct ValidationContext { /* private fields */ }Expand description
Mutable state threaded through prepare and validate.
Implementations§
Source§impl ValidationContext
impl ValidationContext
Sourcepub fn with_strict(self, strict: bool) -> Self
pub fn with_strict(self, strict: bool) -> Self
Force strict (true) or lax (false) mode for every model, like
Pydantic’s model_validate(strict=...).
Sourcepub fn at_root(self, item: impl Into<LocationItem>) -> Self
pub fn at_root(self, item: impl Into<LocationItem>) -> Self
Prefix every reported location with item (e.g. "body").
Sourcepub fn with_data<T: Any + Send + Sync>(self, value: T) -> Self
pub fn with_data<T: Any + Send + Sync>(self, value: T) -> Self
Attach user data readable by validators (Pydantic validation context).
Sourcepub fn config(&self) -> &ModelConfig
pub fn config(&self) -> &ModelConfig
Settings of the model currently being processed.
Sourcepub fn allows_text_coercion(&self) -> bool
pub fn allows_text_coercion(&self) -> bool
Whether lax string → scalar coercion is allowed right now.
Sourcepub fn input_kind(&self) -> InputKind
pub fn input_kind(&self) -> InputKind
Input kind.
Sourcepub fn with_config<R>(
&mut self,
config: ModelConfig,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_config<R>( &mut self, config: ModelConfig, f: impl FnOnce(&mut Self) -> R, ) -> R
Run f with config installed, restoring the previous one after.
Sourcepub fn at<R>(
&mut self,
item: impl Into<LocationItem>,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn at<R>( &mut self, item: impl Into<LocationItem>, f: impl FnOnce(&mut Self) -> R, ) -> R
Run f with item appended to the current location.
Sourcepub fn location(&self) -> &[LocationItem]
pub fn location(&self) -> &[LocationItem]
Current location.
Sourcepub fn error(
&mut self,
code: impl Into<Cow<'static, str>>,
message: impl Into<String>,
)
pub fn error( &mut self, code: impl Into<Cow<'static, str>>, message: impl Into<String>, )
Record an error at the current location.
Sourcepub fn push(&mut self, error: FieldError)
pub fn push(&mut self, error: FieldError)
Record error, prefixing its location with the current location.
Sourcepub fn check(&mut self, result: Result<(), FieldError>)
pub fn check(&mut self, result: Result<(), FieldError>)
Record the result of a rule check at the current location.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Whether any error has been recorded.
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
Number of errors recorded so far (useful to detect new ones).
Sourcepub fn take_errors(&mut self) -> ValidationError
pub fn take_errors(&mut self) -> ValidationError
Take the collected errors, leaving the context empty of errors.