File tree Expand file tree Collapse file tree 1 file changed +1
-21
lines changed Expand file tree Collapse file tree 1 file changed +1
-21
lines changed Original file line number Diff line number Diff line change @@ -243,27 +243,7 @@ to know more about [operator traits][operators-and-overloading].
243
243
# Rules for implementing traits
244
244
245
245
So far, we’ve only added trait implementations to structs, but you can
246
- implement a trait for any type. So technically, we _ could_ implement ` HasArea `
247
- for ` i32 ` :
248
-
249
- ``` rust
250
- trait HasArea {
251
- fn area (& self ) -> f64 ;
252
- }
253
-
254
- impl HasArea for i32 {
255
- fn area (& self ) -> f64 {
256
- println! (" this is silly" );
257
-
258
- * self as f64
259
- }
260
- }
261
-
262
- 5. area ();
263
- ```
264
-
265
- It is considered poor style to implement methods on such primitive types, even
266
- though it is possible.
246
+ implement a trait for any type such as ` i32 ` .
267
247
268
248
This may seem like the Wild West, but there are two restrictions around
269
249
implementing traits that prevent this from getting out of hand. The first is
You can’t perform that action at this time.
0 commit comments