pub struct ValidationContext { /* private fields */ }Expand description
Context for validation operations.
Provides runtime state during validation, including:
- Field values for cross-field validation
- Metadata storage
- Locale settings for i18n
§Example
use skp_validator_core::ValidationContext;
let ctx = ValidationContext::new()
.with_locale("en")
.with_meta("request_id", "123");Implementations§
Source§impl ValidationContext
impl ValidationContext
Sourcepub fn new() -> ValidationContext
pub fn new() -> ValidationContext
Create a new empty validation context
Sourcepub fn with_locale(self, locale: impl Into<String>) -> ValidationContext
pub fn with_locale(self, locale: impl Into<String>) -> ValidationContext
Set the locale for error messages
Sourcepub fn with_fail_fast(self, fail_fast: bool) -> ValidationContext
pub fn with_fail_fast(self, fail_fast: bool) -> ValidationContext
Set fail-fast mode (stop on first error)
Sourcepub fn with_meta(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> ValidationContext
pub fn with_meta( self, key: impl Into<String>, value: impl Into<String>, ) -> ValidationContext
Add metadata
Sourcepub fn with_custom_data<T>(self, data: T) -> ValidationContext
pub fn with_custom_data<T>(self, data: T) -> ValidationContext
Set custom data (type-erased)
Sourcepub fn is_fail_fast(&self) -> bool
pub fn is_fail_fast(&self) -> bool
Check if fail-fast mode is enabled
Sourcepub fn get_custom_data<T>(&self) -> Option<&T>
pub fn get_custom_data<T>(&self) -> Option<&T>
Get custom data by type
Sourcepub fn from_json(json: &Value) -> ValidationContext
pub fn from_json(json: &Value) -> ValidationContext
Create context from a JSON value (requires serde feature)
Sourcepub fn from_serde<T>(data: &T) -> Result<ValidationContext, Error>where
T: Serialize,
pub fn from_serde<T>(data: &T) -> Result<ValidationContext, Error>where
T: Serialize,
Create context from a serializable object (requires serde feature)
Sourcepub fn get_field(&self, name: &str) -> Option<&Value>
pub fn get_field(&self, name: &str) -> Option<&Value>
Get a field value as JSON (requires serde feature)
Sourcepub fn set_field(&mut self, name: impl Into<String>, value: Value)
pub fn set_field(&mut self, name: impl Into<String>, value: Value)
Set a field value (requires serde feature)
Sourcepub fn with_field(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> ValidationContext
pub fn with_field( self, name: impl Into<String>, value: impl Into<String>, ) -> ValidationContext
Set a field value (builder pattern, requires serde feature)
Sourcepub fn get_string(&self, name: &str) -> Option<&str>
pub fn get_string(&self, name: &str) -> Option<&str>
Get a field value as string (requires serde feature)
Sourcepub fn get_i64(&self, name: &str) -> Option<i64>
pub fn get_i64(&self, name: &str) -> Option<i64>
Get a field value as i64 (requires serde feature)
Sourcepub fn get_f64(&self, name: &str) -> Option<f64>
pub fn get_f64(&self, name: &str) -> Option<f64>
Get a field value as f64 (requires serde feature)
Sourcepub fn get_bool(&self, name: &str) -> Option<bool>
pub fn get_bool(&self, name: &str) -> Option<bool>
Get a field value as bool (requires serde feature)
Sourcepub fn has_value(&self, name: &str) -> bool
pub fn has_value(&self, name: &str) -> bool
Check if a field exists and is not null/empty (requires serde feature)
Sourcepub fn is_empty(&self, name: &str) -> bool
pub fn is_empty(&self, name: &str) -> bool
Check if a field is empty or null (requires serde feature)
Sourcepub fn field_names(&self) -> impl Iterator<Item = &String>
pub fn field_names(&self) -> impl Iterator<Item = &String>
Get all field names
Trait Implementations§
Source§impl Clone for ValidationContext
impl Clone for ValidationContext
Source§fn clone(&self) -> ValidationContext
fn clone(&self) -> ValidationContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more