Skip to main content

Validate

Trait Validate 

Source
pub trait Validate {
    // Provided method
    fn validate<'a>(&self, _errors: ErrorCollector<'a>) { ... }
}
Expand description

Validation trait for configuration values.

Configuration is primarily validated with JSON Schema. But not all invalid configurations can be prevented that way – for example, encoding a constraint across different members of an object can be difficult or impossible. The Validate trait supports running additional validations on top of JSON Schema.

Most of the time, you should not use the Validate trait directly, but instead use #[config(validate)] attributes. You can implement the Validate trait to use a custom type as a configuration value.

§Lifecycle

Custom validation works on the actual Rust types. This means that any error that occurs before values are deserialized into Rust types short-circuits validation. Custom validation can only enforce additional constraints on top of the other steps.

One way this can manifest is that a user might get a single JSON schema validation error for a field, but once they fix it, they might start getting an unrelated custom validation error for a different field. This is similar to how fixing a function signature error in your Rust code can make your code reach the “next stage” of compilation, so after fixing the one error you might get dozens of new borrow-checker errors.

Provided Methods§

Source

fn validate<'a>(&self, _errors: ErrorCollector<'a>)

The default implementation of validate accepts all inputs.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Validate for ()

Source§

impl Validate for NonZeroI8

Source§

impl Validate for NonZeroI16

Source§

impl Validate for NonZeroI32

Source§

impl Validate for NonZeroI64

Source§

impl Validate for NonZeroIsize

Source§

impl Validate for NonZeroU8

Source§

impl Validate for NonZeroU16

Source§

impl Validate for NonZeroU32

Source§

impl Validate for NonZeroU64

Source§

impl Validate for NonZeroUsize

Source§

impl Validate for String

Source§

impl Validate for bool

Source§

impl Validate for i8

Source§

impl Validate for i16

Source§

impl Validate for i32

Source§

impl Validate for i64

Source§

impl Validate for isize

Source§

impl Validate for str

Source§

impl Validate for u8

Source§

impl Validate for u16

Source§

impl Validate for u32

Source§

impl Validate for u64

Source§

impl Validate for usize

Source§

impl<K, V, S> Validate for HashMap<K, V, S>
where K: Eq + Hash + AsRef<str> + Validate, V: Validate, S: BuildHasher,

Source§

fn validate(&self, errors: ErrorCollector<'_>)

Source§

impl<T: Validate, R> Validate for Redacted<T, R>

Source§

fn validate<'a>(&self, errors: ErrorCollector<'a>)

Source§

impl<T: Validate> Validate for Arc<T>

Source§

fn validate(&self, errors: ErrorCollector<'_>)

Source§

impl<T: Validate> Validate for Box<T>

Source§

fn validate(&self, errors: ErrorCollector<'_>)

Source§

impl<T: Validate> Validate for Option<T>

Source§

fn validate(&self, errors: ErrorCollector<'_>)

Source§

impl<T: Validate> Validate for Vec<T>

Source§

fn validate(&self, errors: ErrorCollector<'_>)

Implementors§