diff --git a/src/rule/collection/count.rs b/src/rule/collection/count.rs index fd198ad..6da2f85 100644 --- a/src/rule/collection/count.rs +++ b/src/rule/collection/count.rs @@ -1,7 +1,9 @@ mod equal; +mod grater_equal; mod greater; mod less; pub use equal::*; +pub use grater_equal::*; pub use greater::*; pub use less::*; diff --git a/src/rule/collection/count/grater_equal.rs b/src/rule/collection/count/grater_equal.rs new file mode 100644 index 0000000..d29e56d --- /dev/null +++ b/src/rule/collection/count/grater_equal.rs @@ -0,0 +1,80 @@ +use crate::rule::{CountEqualRule, CountGreaterRule}; +use crate::{Or, Refined}; + +/// A type that holds a value satisfying the `GreaterEqualRule` +pub type CountGreaterEqual = + Refined>; + +/// A type that holds a `Vec` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualVec = Refined>; + +/// A type that holds a `VecDeque` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualVecDeque = + Refined>; + +/// A type that holds a `HashMap` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualHashMap = + Refined>; + +/// A type that holds a `HashSet` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualHashSet = + Refined>; + +/// A type that holds a `String` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualString = + Refined>; + +/// A type that holds a `&'a str` value satisfying the `CountGreaterEqualRule` +pub type CountGreaterEqualStr<'a, const N: usize, RULE> = + Refined>; + +/// Rule where the count of items in the collection that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualRule = + Or![CountGreaterRule, CountEqualRule]; + +/// Rule where the count of items in the `Vec` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualVecRule = + CountGreaterEqualRule::Item>>; + +/// Rule where the count of items in the `VecDeque` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualVecDequeRule = + CountGreaterEqualRule::Item>>; + +/// Rule where the count of items in the `HashMap` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualHashMapRule = + CountGreaterEqualRule::Item>>; + +/// Rule where the count of items in the `HashSet` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualHashSetRule = + CountGreaterEqualRule>; + +/// Rule where the count of items in the `String` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualStringRule = CountGreaterEqualRule; + +/// Rule where the count of items in the `&'a str` that satisfy the condition is greater than or equal to `N`. +pub type CountGreaterEqualStrRule<'a, const N: usize, RULE> = + CountGreaterEqualRule; + +#[cfg(test)] +mod tests { + use crate::result::Error; + use crate::rule::{CountGreaterEqualVec, NonEmptyStringRule}; + + #[test] + fn count_greater_equal_1() -> Result<(), Error>> { + let value = vec!["good morning".to_string(), "hello".to_string()]; + let count_greater_equal: CountGreaterEqualVec<2, NonEmptyStringRule> = + CountGreaterEqualVec::new(value.clone())?; + assert_eq!(count_greater_equal.into_value(), value); + Ok(()) + } + + #[test] + fn count_greater_equal_2() -> anyhow::Result<()> { + let value = vec!["".to_string(), "".to_string()]; + let count_greater_equal_result = + CountGreaterEqualVec::<2, NonEmptyStringRule>::new(value.clone()); + assert!(count_greater_equal_result.is_err()); + Ok(()) + } +}