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§
Sourcefn validate<'a>(&self, _errors: ErrorCollector<'a>)
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".