1pub trait Zero {
7 fn zero () -> Self;
8}
9
10pub trait One {
12 fn one () -> Self;
13}
14
15macro_rules! impl_zero_one_int {
16 ($($ty:ty),*) => { $(
17 impl Zero for $ty {
18 fn zero () -> $ty { 0 }
19 }
20
21 impl One for $ty {
22 fn one() -> $ty { 1 }
23 }
24 )* };
25}
26
27macro_rules! impl_zero_one_float {
28 ($($ty:ty),*) => { $(
29 impl Zero for $ty {
30 fn zero () -> $ty { 0.0 }
31 }
32
33 impl One for $ty {
34 fn one () -> $ty { 1.0 }
35 }
36 )* };
37}
38
39impl_zero_one_int!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
40impl_zero_one_float!(f32, f64);