icydb_base/validator/
collection.rs1use crate::{core::traits::Validator, prelude::*};
2
3#[validator]
8pub struct InArray<T> {
9 pub 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) -> Result<(), String> {
24 if self.values.contains(n) {
25 Ok(())
26 } else {
27 Err(format!(
28 "{n} is not in the allowed values: {:?}",
29 self.values
30 ))
31 }
32 }
33}