icydb/base/validator/
collection.rs

1use crate::{design::prelude::*, traits::Validator, visitor::VisitorContext};
2
3///
4/// InArray
5///
6
7#[validator]
8pub struct InArray<T> {
9    values: Vec<T>,
10}
11
12impl<T> InArray<T> {
13    #[must_use]
14    pub const fn new(values: Vec<T>) -> Self {
15        Self { values }
16    }
17}
18
19impl<T> Validator<T> for InArray<T>
20where
21    T: PartialEq + std::fmt::Debug + std::fmt::Display,
22{
23    fn validate(&self, n: &T, ctx: &mut dyn VisitorContext) {
24        if !self.values.contains(n) {
25            ctx.issue(format!(
26                "{n} is not in the allowed values: {:?}",
27                self.values
28            ));
29        }
30    }
31}