@@ -6,28 +6,41 @@ pub trait One {
66 fn one ( ) -> Self ;
77}
88
9- impl Zero for u8 { fn zero ( ) -> Self { 0 } }
10- impl Zero for u16 { fn zero ( ) -> Self { 0 } }
11- impl Zero for u32 { fn zero ( ) -> Self { 0 } }
12- impl Zero for u64 { fn zero ( ) -> Self { 0 } }
13- impl Zero for usize { fn zero ( ) -> Self { 0 } }
14- impl Zero for i8 { fn zero ( ) -> Self { 0 } }
15- impl Zero for i16 { fn zero ( ) -> Self { 0 } }
16- impl Zero for i32 { fn zero ( ) -> Self { 0 } }
17- impl Zero for i64 { fn zero ( ) -> Self { 0 } }
18- impl Zero for isize { fn zero ( ) -> Self { 0 } }
19- impl Zero for f32 { fn zero ( ) -> Self { 0.0 } }
20- impl Zero for f64 { fn zero ( ) -> Self { 0.0 } }
9+ macro_rules! zero_impl {
10+ ( $t: ident, $z: expr ) => (
11+ impl Zero for $t { fn zero( ) -> Self { $z } }
12+ )
13+ }
14+
15+ zero_impl ! ( u8 , 0 ) ;
16+ zero_impl ! ( u16 , 0 ) ;
17+ zero_impl ! ( u32 , 0 ) ;
18+ zero_impl ! ( u64 , 0 ) ;
19+ zero_impl ! ( usize , 0 ) ;
20+ zero_impl ! ( i8 , 0 ) ;
21+ zero_impl ! ( i16 , 0 ) ;
22+ zero_impl ! ( i32 , 0 ) ;
23+ zero_impl ! ( i64 , 0 ) ;
24+ zero_impl ! ( isize , 0 ) ;
25+ zero_impl ! ( f32 , 0.0 ) ;
26+ zero_impl ! ( f64 , 0.0 ) ;
27+
28+
29+ macro_rules! one_impl {
30+ ( $t: ident, $o: expr ) => (
31+ impl One for $t { fn one( ) -> Self { $o } }
32+ )
33+ }
2134
22- impl One for u8 { fn one ( ) -> Self { 1 } }
23- impl One for u16 { fn one ( ) -> Self { 1 } }
24- impl One for u32 { fn one ( ) -> Self { 1 } }
25- impl One for u64 { fn one ( ) -> Self { 1 } }
26- impl One for usize { fn one ( ) -> Self { 1 } }
27- impl One for i8 { fn one ( ) -> Self { 1 } }
28- impl One for i16 { fn one ( ) -> Self { 1 } }
29- impl One for i32 { fn one ( ) -> Self { 1 } }
30- impl One for i64 { fn one ( ) -> Self { 1 } }
31- impl One for isize { fn one ( ) -> Self { 1 } }
32- impl One for f32 { fn one ( ) -> Self { 1.0 } }
33- impl One for f64 { fn one ( ) -> Self { 1.0 } }
35+ one_impl ! ( u8 , 1 ) ;
36+ one_impl ! ( u16 , 1 ) ;
37+ one_impl ! ( u32 , 1 ) ;
38+ one_impl ! ( u64 , 1 ) ;
39+ one_impl ! ( usize , 1 ) ;
40+ one_impl ! ( i8 , 1 ) ;
41+ one_impl ! ( i16 , 1 ) ;
42+ one_impl ! ( i32 , 1 ) ;
43+ one_impl ! ( i64 , 1 ) ;
44+ one_impl ! ( isize , 1 ) ;
45+ one_impl ! ( f32 , 1.0 ) ;
46+ one_impl ! ( f64 , 1.0 ) ;
0 commit comments