File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,6 +33,36 @@ pub trait Size:
3333 fn display ( self , input : Self :: DisplayFormat ) -> Self :: DisplayOutput ;
3434}
3535
36+ macro_rules! impl_mul {
37+ ( $name: ident: $inner: ident *= $( $num_type: ident) +) => {
38+ $(
39+ impl Mul <$num_type> for $name {
40+ type Output = Self ;
41+ fn mul( self , rhs: $num_type) -> Self :: Output {
42+ self . 0 . mul( rhs as $inner) . into( )
43+ }
44+ }
45+
46+ impl Mul <$name> for $num_type {
47+ type Output = $name;
48+ fn mul( self , rhs: $name) -> Self :: Output {
49+ rhs * self
50+ }
51+ }
52+
53+ impl MulAssign <$num_type> for $name {
54+ fn mul_assign( & mut self , rhs: $num_type) {
55+ self . 0 *= rhs as $inner;
56+ }
57+ }
58+ ) +
59+ } ;
60+
61+ ( $name: ident: u64 ) => {
62+ impl_mul!( $name: u64 *= u8 u16 u32 u64 ) ;
63+ } ;
64+ }
65+
3666macro_rules! newtype {
3767 (
3868 $( #[ $attribute: meta] ) *
@@ -65,25 +95,7 @@ macro_rules! newtype {
6595 }
6696 }
6797
68- impl Mul <$inner> for $name {
69- type Output = Self ;
70- fn mul( self , rhs: $inner) -> Self :: Output {
71- self . 0 . mul( rhs) . into( )
72- }
73- }
74-
75- impl Mul <$name> for $inner {
76- type Output = $name;
77- fn mul( self , rhs: $name) -> Self :: Output {
78- rhs * self
79- }
80- }
81-
82- impl MulAssign <$inner> for $name {
83- fn mul_assign( & mut self , rhs: $inner) {
84- self . 0 *= rhs;
85- }
86- }
98+ impl_mul!( $name: u64 ) ;
8799 } ;
88100}
89101
You can’t perform that action at this time.
0 commit comments