-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from tomoikey/feat/less_greater_than
Feat/less greater than
- Loading branch information
Showing
10 changed files
with
254 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
mod equal; | ||
mod even; | ||
mod greater; | ||
mod greater_equal; | ||
mod less; | ||
mod less_equal; | ||
mod min_max; | ||
mod odd; | ||
mod range; | ||
|
||
pub use equal::*; | ||
pub use even::*; | ||
pub use greater::*; | ||
pub use greater_equal::*; | ||
pub use less::*; | ||
pub use less_equal::*; | ||
pub use min_max::*; | ||
pub use odd::*; | ||
pub use range::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
macro_rules! declare_greater_equal_rule { | ||
($ty: ty) => { | ||
$crate::paste::item! { | ||
/// A type that holds a value satisfying the `GreaterEqualRule` | ||
pub type [<GreaterEqual $ty:camel>]<const N: $ty> = $crate::Refined<[<GreaterEqualRule $ty:camel>]<N>>; | ||
|
||
/// Rule where the target value must be greater than or equal to `N` | ||
pub type [<GreaterEqualRule $ty:camel>]<const N: $ty> = $crate::Or![$crate::rule::[<EqualRule $ty:camel>]<N>, $crate::rule::[<GreaterRule $ty:camel>]<N>]; | ||
} | ||
}; | ||
($t: ty, $($ts: ty),+) => { | ||
declare_greater_equal_rule!($t); | ||
declare_greater_equal_rule!($($ts), +); | ||
}; | ||
} | ||
|
||
declare_greater_equal_rule!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::rule::GreaterEqualU8; | ||
|
||
#[test] | ||
fn test_greater_equal_than_50u8_ok() { | ||
let greater_equal_result = GreaterEqualU8::<50>::new(50); | ||
assert!(greater_equal_result.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn test_greater_equal_than_50u8_err() { | ||
let greater_equal_result = GreaterEqualU8::<50>::new(49); | ||
assert!(greater_equal_result.is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
macro_rules! declare_less_equal_rule { | ||
($ty: ty) => { | ||
$crate::paste::item! { | ||
/// A type that holds a value satisfying the `LessEqualRule` | ||
pub type [<LessEqual $ty:camel>]<const N: $ty> = $crate::Refined<[<LessEqualRule $ty:camel>]<N>>; | ||
|
||
/// Rule where the target value must be less than or equal to `N` | ||
pub type [<LessEqualRule $ty:camel>]<const N: $ty> = $crate::Or![$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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
macro_rules! define_range_rule { | ||
($t: ty) => { | ||
$crate::paste::item! { | ||
/// A type that holds a value satisfying the `RangeRule` | ||
pub type [<Range $t:camel>]<const FROM: $t, const UNTIL: $t> = $crate::Refined<[<RangeRule $t:camel>]<FROM, UNTIL>>; | ||
|
||
/// Rule where the target value must be greater than or equal to `FROM` and less than `UNTIL` | ||
pub type [<RangeRule $t:camel>]<const FROM: $t, const UNTIL: $t> = $crate::And![ | ||
$crate::rule::[<GreaterEqualRule $t:camel>]<FROM>, | ||
$crate::rule::[<LessRule $t:camel>]<UNTIL> | ||
]; | ||
} | ||
}; | ||
($t: ty, $($ts: ty),+) => { | ||
define_range_rule!($t); | ||
define_range_rule!($($ts), +); | ||
}; | ||
} | ||
|
||
define_range_rule!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize); | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::rule::RangeI8; | ||
|
||
#[test] | ||
fn test_range_i8_ok() { | ||
let range_result = RangeI8::<1, 10>::new(0); | ||
assert!(range_result.is_err()); | ||
|
||
let range_result = RangeI8::<1, 10>::new(1); | ||
assert!(range_result.is_ok()); | ||
|
||
let range_result = RangeI8::<1, 10>::new(10); | ||
assert!(range_result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_range_i8_err() { | ||
let range_result = RangeI8::<1, 10>::new(-1); | ||
assert!(range_result.is_err()); | ||
|
||
let range_result = RangeI8::<1, 10>::new(11); | ||
assert!(range_result.is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters