Skip to content

Commit

Permalink
Merge pull request #71 from JulesGuesnon/main
Browse files Browse the repository at this point in the history
[Feat] Supporting f32 and f64 for range
  • Loading branch information
jprochazk authored Oct 18, 2023
2 parents 1c2a13f + 990401f commit bc759ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion garde/src/rules/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ macro_rules! impl_for_int {
};
}

impl_for_int!(u8, u16, u32, u64, usize, u128, i8, i16, i32, i64, isize, i128);
impl_for_int!(u8, u16, u32, u64, usize, u128, i8, i16, i32, i64, isize, i128, f32, f64);

impl<T: Bounds> Bounds for Option<T> {
type Size = T::Size;
Expand Down
9 changes: 7 additions & 2 deletions garde/tests/rules/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ struct Test<'a> {
refers_to_field: u64,
#[garde(inner(range(min = 10, max = 100)))]
inner: &'a [u64],
#[garde(range(min = 0., max = 100.))]
float_field: f32,
}

#[test]
Expand All @@ -16,6 +18,7 @@ fn range_valid() {
field: 50,
refers_to_field: 10,
inner: &[50],
float_field: 10.,
}],
&(),
)
Expand All @@ -28,12 +31,14 @@ fn range_invalid() {
Test {
field: 9,
refers_to_field: 10,
inner: &[9]
inner: &[9],
float_field: -12.
},
Test {
field: 101,
refers_to_field: 200,
inner: &[101]
inner: &[101],
float_field: 1204.
}
],
&()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Test {
inner: [
9,
],
float_field: -12.0,
}
field: lower than 10
float_field: lower than 0
inner[0]: lower than 10
refers_to_field: greater than 9

Expand All @@ -19,8 +21,10 @@ Test {
inner: [
101,
],
float_field: 1204.0,
}
field: greater than 100
float_field: greater than 100
inner[0]: greater than 100
refers_to_field: greater than 101

Expand Down

0 comments on commit bc759ce

Please sign in to comment.