@@ -142,38 +142,46 @@ conversions! {
142
142
varries [ usize ]
143
143
}
144
144
145
- // NB: We do not provide the transparent-ref impls like the stdlib does.
146
- impl Add for TextSize {
147
- type Output = TextSize ;
148
- fn add ( self , rhs : TextSize ) -> TextSize {
149
- TextSize ( self . raw + rhs. raw )
150
- }
151
- }
152
-
153
- impl < A > AddAssign < A > for TextSize
154
- where
155
- TextSize : Add < A , Output = TextSize > ,
156
- {
157
- fn add_assign ( & mut self , rhs : A ) {
158
- * self = * self + rhs
159
- }
160
- }
145
+ macro_rules! arith {
146
+ ( $Op: ident $op: ident, $OpAssign: ident $op_assign: ident) => {
147
+ impl $Op<TextSize > for TextSize {
148
+ type Output = TextSize ;
149
+ fn $op( self , rhs: TextSize ) -> TextSize {
150
+ TextSize ( $Op:: $op( self . raw, rhs. raw) )
151
+ }
152
+ }
153
+ impl $Op<TextSize > for & ' _ TextSize {
154
+ type Output = TextSize ;
155
+ fn $op( self , rhs: TextSize ) -> TextSize {
156
+ TextSize ( $Op:: $op( self . raw, rhs. raw) )
157
+ }
158
+ }
159
+ impl $Op<& ' _ TextSize > for TextSize {
160
+ type Output = TextSize ;
161
+ fn $op( self , rhs: & TextSize ) -> TextSize {
162
+ TextSize ( $Op:: $op( self . raw, rhs. raw) )
163
+ }
164
+ }
165
+ impl $Op<& ' _ TextSize > for & ' _ TextSize {
166
+ type Output = TextSize ;
167
+ fn $op( self , rhs: & TextSize ) -> TextSize {
168
+ TextSize ( $Op:: $op( self . raw, rhs. raw) )
169
+ }
170
+ }
161
171
162
- impl Sub for TextSize {
163
- type Output = TextSize ;
164
- fn sub ( self , rhs : TextSize ) -> TextSize {
165
- TextSize ( self . raw - rhs. raw )
166
- }
172
+ impl <A > $OpAssign<A > for TextSize
173
+ where
174
+ TextSize : $Op<A , Output = TextSize >,
175
+ {
176
+ fn $op_assign( & mut self , rhs: A ) {
177
+ * self = $Op:: $op( * self , rhs)
178
+ }
179
+ }
180
+ } ;
167
181
}
168
182
169
- impl < S > SubAssign < S > for TextSize
170
- where
171
- TextSize : Sub < S , Output = TextSize > ,
172
- {
173
- fn sub_assign ( & mut self , rhs : S ) {
174
- * self = * self - rhs
175
- }
176
- }
183
+ arith ! ( Add add, AddAssign add_assign) ;
184
+ arith ! ( Sub sub, SubAssign sub_assign) ;
177
185
178
186
impl < A > iter:: Sum < A > for TextSize
179
187
where
0 commit comments