Skip to content

Commit

Permalink
implement feat less_than
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Oct 29, 2024
1 parent 0014a61 commit 399a1ae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rule/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ mod equal;
mod even;
mod greater;
mod less;
mod less_equal;
mod min_max;
mod odd;

pub use equal::*;
pub use even::*;
pub use greater::*;
pub use less::*;
pub use less_equal::*;
pub use min_max::*;
pub use odd::*;
39 changes: 39 additions & 0 deletions src/rule/number/less_equal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::{And, Refined};
use crate::rule::{EqualRuleU8, LessRuleU8};

pub type LessEqualU8<const N: u8> = Refined<LessEqualRuleU8<N>>;

pub type LessEqualRuleU8<const N: u8> = And![EqualRuleU8<N>, LessRuleU8<N>];

macro_rules! declare_less_equal_rule {
($ty: ty) => {
$crate::paste::item! {
pub type [<LessEqual $ty>]<const N: $ty> = $crate::Refined<[<LessEqualRule $ty>]<N>>;

pub type [<LessEqualRule $ty>]<const N: $ty> = $crate::And![$crate::rule::[<EqualRule $ty:camel>]<N>, $crate::rule::[<LessRule $ty:camel>]<N>];
}
};
($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());
}
}

0 comments on commit 399a1ae

Please sign in to comment.