Skip to main content

Validate

Trait Validate 

Source
pub trait Validate<T: ?Sized>:
    'static
    + Send
    + Sync {
    // Required methods
    fn describe(&self, formatter: &mut Formatter<'_>) -> Result;
    fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>;
}
Expand description

Generic post-validation for a configuration parameter or a config.

§Implementations

Validations are implemented for the following types:

  • NotEmpty. Validates that a string or a collection, such as Vec, is not empty.
  • Range, RangeInclusive etc. Validates whether the type is within the provided bounds.

Required Methods§

Source

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Describes this validation.

§Errors

Should propagate formatting errors.

Source

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Validates a parameter / config.

§Errors

Should return an error if validation fails.

Trait Implementations§

Source§

impl<T: 'static + ?Sized> Debug for dyn Validate<T>

Source§

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

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

impl<T: 'static + ?Sized> Display for dyn Validate<T>

Source§

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

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: ?Sized, V: Validate<T> + ?Sized> Validate<T> for &'static V

Delegates via a reference. Useful for defining validation constants as &'static dyn Validate<_>.

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Source§

impl<T> Validate<T> for Range<T>
where T: 'static + Send + Sync + PartialOrd + Debug,

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Source§

impl<T> Validate<T> for RangeFrom<T>
where T: 'static + Send + Sync + PartialOrd + Debug,

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Source§

impl<T> Validate<T> for RangeInclusive<T>
where T: 'static + Send + Sync + PartialOrd + Debug,

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Source§

impl<T> Validate<T> for RangeTo<T>
where T: 'static + Send + Sync + PartialOrd + Debug,

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Source§

impl<T> Validate<T> for RangeToInclusive<T>
where T: 'static + Send + Sync + PartialOrd + Debug,

Source§

fn describe(&self, formatter: &mut Formatter<'_>) -> Result

Source§

fn validate(&self, target: &T) -> Result<(), ErrorWithOrigin>

Implementors§

Source§

impl Validate<String> for NotEmpty

Source§

impl<K, S> Validate<HashSet<K, S>> for NotEmpty

Source§

impl<K, V, S> Validate<HashMap<K, V, S>> for NotEmpty

Source§

impl<K, V> Validate<BTreeMap<K, V>> for NotEmpty

Source§

impl<K> Validate<BTreeSet<K>> for NotEmpty

Source§

impl<T> Validate<String> for LazyRegex<T>
where T: Deref<Target = Regex> + Send + Sync + 'static,

Validates that the string matches the provided regex.

Don’t forget to surround the regex with ^$ if you want to match it completely.

Source§

impl<T> Validate<Vec<T>> for NotEmpty