Tutorial by Examples

Rust's From trait is a general-purpose trait for converting between types. For any two types TypeA and TypeB, impl From<TypeA> for TypeB indicates that an instance of TypeB is guaranteed to be constructible from an instance of TypeA. An implementation of From looks like this: struct TypeA...
std::convert::AsRef and std::convert::AsMut are used for cheaply converting types to references. For types A and B, impl AsRef<B> for A indicates that a &A can be converted to a &B and, impl AsMut<B> for A indicates that a &mut A can be converted to a &mut B. Thi...
The std::borrow::Borrow and std::borrow::BorrowMut traits are used to treat borrowed types like owned types. For types A and B, impl Borrow<B> for A indicates that a borrowed A may be used where a B is desired. For instance, std::collections::HashMap.get() uses Borrow for its get() method,...
The std::ops::Deref and std::ops::DerefMut traits are used for overloading the dereference operator, *x. For types A and B, impl Deref<Target=B> for A indicates that dereferencing a binding of &A will yield a &B and, impl DerefMut for A indicates that dereferencing a binding of...

Page 1 of 1