diff --git a/src/rule/number.rs b/src/rule/number.rs index ff0f138..521f298 100644 --- a/src/rule/number.rs +++ b/src/rule/number.rs @@ -2,6 +2,7 @@ mod equal; mod even; mod greater; mod less; +mod less_equal; mod min_max; mod odd; @@ -9,5 +10,6 @@ pub use equal::*; pub use even::*; pub use greater::*; pub use less::*; +pub use less_equal::*; pub use min_max::*; pub use odd::*; diff --git a/src/rule/number/less_equal.rs b/src/rule/number/less_equal.rs new file mode 100644 index 0000000..1de91b1 --- /dev/null +++ b/src/rule/number/less_equal.rs @@ -0,0 +1,39 @@ +use crate::{And, Refined}; +use crate::rule::{EqualRuleU8, LessRuleU8}; + +pub type LessEqualU8 = Refined>; + +pub type LessEqualRuleU8 = And![EqualRuleU8, LessRuleU8]; + +macro_rules! declare_less_equal_rule { + ($ty: ty) => { + $crate::paste::item! { + pub type [] = $crate::Refined<[]>; + + pub type [] = $crate::And![$crate::rule::[], $crate::rule::[]]; + } + }; + ($t: ty, $($ts: ty),+) => { + declare_less_equal_rule!($t); + declare_less_equal_rule!($($ts), +); + }; +} + +declare_less_equal_rule!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); + +#[cfg(test)] +mod test { + use crate::rule::LessEqualU8; + + #[test] + fn test_less_equal_than_50u8_ok() { + let less_equal_result = LessEqualU8::<50>::new(50); + assert!(less_equal_result.is_ok()); + } + + #[test] + fn test_less_equal_than_50u8_err() { + let less_equal_result = LessEqualU8::<50>::new(51); + assert!(less_equal_result.is_err()); + } +} \ No newline at end of file