From 1b39c0a602ad316b8eebd2dd50ae14e45d47dd13 Mon Sep 17 00:00:00 2001 From: nwin Date: Mon, 31 Oct 2016 19:43:50 +0100 Subject: [PATCH] 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. --- src/doc/book/traits.md | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/doc/book/traits.md b/src/doc/book/traits.md index b0d954adf677..18e7f07f722e 100644 --- a/src/doc/book/traits.md +++ b/src/doc/book/traits.md @@ -243,27 +243,7 @@ to know more about [operator traits][operators-and-overloading]. # Rules for implementing traits So far, we’ve only added trait implementations to structs, but you can -implement a trait for any type. So technically, we _could_ implement `HasArea` -for `i32`: - -```rust -trait HasArea { - fn area(&self) -> f64; -} - -impl HasArea for i32 { - fn area(&self) -> f64 { - println!("this is silly"); - - *self as f64 - } -} - -5.area(); -``` - -It is considered poor style to implement methods on such primitive types, even -though it is possible. +implement a trait for any type such as `i32`. This may seem like the Wild West, but there are two restrictions around implementing traits that prevent this from getting out of hand. The first is