January 2019
Beginner to intermediate
554 pages
13h 31m
English
To provide similar behavior as normal pointers, that is, to be able to dereference the call methods on the underlying type being pointed to, smart pointer types often implement the Deref trait, which allows us to use the * dereferencing operator with these types. While Deref gives you read-only access, there is also DerefMut, which can give you a mutable reference to the underlying type. Deref has the following type signature:
pub trait Deref { type Target: ?Sized; fn deref(&self) -> &Self::Target;}
If defines a single method called Deref that takes self by reference and returns a immutable reference to the underlying type. This combined with the deref coercion feature of Rust, reduces a lot of code that you have to write. ...
Read now
Unlock full access