1pub trait Bounded {
3 fn max_value() -> Self;
4 fn min_value() -> Self;
5}
6
7macro_rules! bounded_impl {
8 ($t:ident) => {
9 impl Bounded for $t {
10 #[inline]
11 fn max_value() -> Self {
12 $t::MAX
13 }
14
15 #[inline]
16 fn min_value() -> Self {
17 $t::MIN
18 }
19 }
20 };
21}
22
23bounded_impl!(u8);
24bounded_impl!(u16);
25bounded_impl!(u32);
26bounded_impl!(u64);
27bounded_impl!(u128);
28bounded_impl!(usize);
29bounded_impl!(i8);
30bounded_impl!(i16);
31bounded_impl!(i32);
32bounded_impl!(i64);
33bounded_impl!(i128);
34bounded_impl!(isize);
35
36impl Bounded for f64 {
37 #[inline]
38 fn max_value() -> Self {
39 1.0
40 }
41
42 #[inline]
43 fn min_value() -> Self {
44 0.0
45 }
46}
47
48impl Bounded for f32 {
49 #[inline]
50 fn max_value() -> Self {
51 1.0
52 }
53
54 #[inline]
55 fn min_value() -> Self {
56 0.0
57 }
58}