pretzelhammer / rust-blog

Educational blog posts for Rust beginners
Apache License 2.0
7.58k stars 401 forks source link

Misconception discussion: T is a superset of both &T and &mut T #60

Closed wodny closed 2 months ago

wodny commented 2 years ago

While it's true and can be presented with generics, maybe a note that the following is possible would be beneficial, so nobody erroneously extrapolates the rule:

struct Foo();
trait Trait {}
impl Trait for Foo {}
impl Trait for &Foo {}
impl Trait for &mut Foo {}

Like with impl Read for TcpStream and impl Read for &TcpStream.

pretzelhammer commented 2 months ago

https://github.com/pretzelhammer/rust-blog/commit/beab8bae9922f9db7aad0611cb5973d12db718eb