1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
mod max_items;
mod min_items;
mod unique_items;

pub use max_items::ValidateMaxItems;
pub use min_items::ValidateMinItems;
pub use unique_items::ValidateUniqueItems;

use crate::{MaxItemsError, MinItemsError};

macro_rules! impl_validate_array_length_items {
    ($ErrorType:ident) => {
        paste::paste! {
            impl<T> [<Validate $ErrorType>] for Option<T>
            where
                T: [<Validate $ErrorType>],
            {
                fn [<validate_ $ErrorType:snake>] (&self, limit: usize) -> Result<(), [<$ErrorType Error>]> {
                    match self {
                        Some(value) => value.[<validate_ $ErrorType:snake>](limit),
                        None => Ok(()),
                    }
                }
            }
        }
    };
}

impl_validate_array_length_items!(MaxItems);
impl_validate_array_length_items!(MinItems);