Trait smart_config::validation::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

Implementations on Foreign Types§

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>

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>

Implementors§

source§

impl Validate<String> for NotEmpty

source§

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

source§

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

source§

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

source§

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

source§

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