ValidationContext

Struct ValidationContext 

Source
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

Source

pub fn new() -> ValidationContext

Create a new empty validation context

Source

pub fn with_locale(self, locale: impl Into<String>) -> ValidationContext

Set the locale for error messages

Source

pub fn with_fail_fast(self, fail_fast: bool) -> ValidationContext

Set fail-fast mode (stop on first error)

Source

pub fn with_meta( self, key: impl Into<String>, value: impl Into<String>, ) -> ValidationContext

Add metadata

Source

pub fn with_custom_data<T>(self, data: T) -> ValidationContext
where T: Any + Send + Sync,

Set custom data (type-erased)

Source

pub fn locale(&self) -> &str

Get the locale

Source

pub fn is_fail_fast(&self) -> bool

Check if fail-fast mode is enabled

Source

pub fn get_meta(&self, key: &str) -> Option<&str>

Get metadata value

Source

pub fn get_custom_data<T>(&self) -> Option<&T>
where T: Any + Send + Sync,

Get custom data by type

Source

pub fn from_json(json: &Value) -> ValidationContext

Create context from a JSON value (requires serde feature)

Source

pub fn from_serde<T>(data: &T) -> Result<ValidationContext, Error>
where T: Serialize,

Create context from a serializable object (requires serde feature)

Source

pub fn get_field(&self, name: &str) -> Option<&Value>

Get a field value as JSON (requires serde feature)

Source

pub fn set_field(&mut self, name: impl Into<String>, value: Value)

Set a field value (requires serde feature)

Source

pub fn with_field( self, name: impl Into<String>, value: impl Into<String>, ) -> ValidationContext

Set a field value (builder pattern, requires serde feature)

Source

pub fn get_string(&self, name: &str) -> Option<&str>

Get a field value as string (requires serde feature)

Source

pub fn get_i64(&self, name: &str) -> Option<i64>

Get a field value as i64 (requires serde feature)

Source

pub fn get_f64(&self, name: &str) -> Option<f64>

Get a field value as f64 (requires serde feature)

Source

pub fn get_bool(&self, name: &str) -> Option<bool>

Get a field value as bool (requires serde feature)

Source

pub fn has_value(&self, name: &str) -> bool

Check if a field exists and is not null/empty (requires serde feature)

Source

pub fn is_empty(&self, name: &str) -> bool

Check if a field is empty or null (requires serde feature)

Source

pub fn field_names(&self) -> impl Iterator<Item = &String>

Get all field names

Trait Implementations§

Source§

impl Clone for ValidationContext

Source§

fn clone(&self) -> ValidationContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValidationContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for ValidationContext

Source§

fn default() -> ValidationContext

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.