Skip to content

Commit 1b39c0a

Browse files
authored
Remove remark about poor code style
The current wording [seems to be confusing](https://www.reddit.com/r/rust/comments/5aat03/why_is_implementing_traits_on_primitive_types/). As an explanation when and why this could be considered as poor style would go beyond of the scope of this chapter I suggest to remove this remark.
1 parent bf5b824 commit 1b39c0a

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/doc/book/traits.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,7 @@ to know more about [operator traits][operators-and-overloading].
243243
# Rules for implementing traits
244244

245245
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`.
267247

268248
This may seem like the Wild West, but there are two restrictions around
269249
implementing traits that prevent this from getting out of hand. The first is

0 commit comments

Comments
 (0)