@@ -100,46 +100,52 @@ impl From<TextSize> for usize {
100
100
}
101
101
}
102
102
103
- macro_rules! arith {
104
- ( $Op: ident $op : ident , $OpAssign : ident $op_assign : ident ) => {
103
+ macro_rules! ops {
104
+ ( impl $Op: ident for TextSize by fn $f : ident = $op : tt ) => {
105
105
impl $Op<TextSize > for TextSize {
106
106
type Output = TextSize ;
107
- fn $op ( self , rhs : TextSize ) -> TextSize {
108
- TextSize ( $Op :: $op ( self . raw, rhs . raw) )
107
+ fn $f ( self , other : TextSize ) -> TextSize {
108
+ TextSize ( self . raw $op other . raw)
109
109
}
110
110
}
111
- impl $Op<TextSize > for & ' _ TextSize {
111
+ impl $Op<& TextSize > for TextSize {
112
112
type Output = TextSize ;
113
- fn $op ( self , rhs : TextSize ) -> TextSize {
114
- TextSize ( $Op :: $op ( self . raw , rhs . raw ) )
113
+ fn $f ( self , other : & TextSize ) -> TextSize {
114
+ self $op * other
115
115
}
116
116
}
117
- impl $Op<& ' _ TextSize > for TextSize {
118
- type Output = TextSize ;
119
- fn $op( self , rhs: & TextSize ) -> TextSize {
120
- TextSize ( $Op:: $op( self . raw, rhs. raw) )
121
- }
122
- }
123
- impl $Op<& ' _ TextSize > for & ' _ TextSize {
124
- type Output = TextSize ;
125
- fn $op( self , rhs: & TextSize ) -> TextSize {
126
- TextSize ( $Op:: $op( self . raw, rhs. raw) )
127
- }
128
- }
129
-
130
- impl <A > $OpAssign<A > for TextSize
117
+ impl <T > $Op<T > for & TextSize
131
118
where
132
- TextSize : $Op<A , Output = TextSize >,
119
+ TextSize : $Op<T , Output = TextSize >,
133
120
{
134
- fn $op_assign( & mut self , rhs: A ) {
135
- * self = $Op:: $op( * self , rhs)
121
+ type Output = TextSize ;
122
+ fn $f( self , other: T ) -> TextSize {
123
+ * self $op other
136
124
}
137
125
}
138
126
} ;
139
127
}
140
128
141
- arith ! ( Add add, AddAssign add_assign) ;
142
- arith ! ( Sub sub, SubAssign sub_assign) ;
129
+ ops ! ( impl Add for TextSize by fn add = +) ;
130
+ ops ! ( impl Sub for TextSize by fn sub = -) ;
131
+
132
+ impl < A > AddAssign < A > for TextSize
133
+ where
134
+ TextSize : Add < A , Output = TextSize > ,
135
+ {
136
+ fn add_assign ( & mut self , rhs : A ) {
137
+ * self = * self + rhs
138
+ }
139
+ }
140
+
141
+ impl < S > SubAssign < S > for TextSize
142
+ where
143
+ TextSize : Sub < S , Output = TextSize > ,
144
+ {
145
+ fn sub_assign ( & mut self , rhs : S ) {
146
+ * self = * self - rhs
147
+ }
148
+ }
143
149
144
150
impl < A > iter:: Sum < A > for TextSize
145
151
where
0 commit comments