Module device_tree::util::convert
[−]
[src]
Traits for conversions between types.
The traits in this module provide a general way to talk about conversions
from one type to another. They follow the standard Rust conventions of
as
/into
/from
.
Like many traits, these are often used as bounds for generic functions, to support arguments of multiple types.
- Impl the
As*
traits for reference-to-reference conversions - Impl the
Into
trait when you want to consume the value in the conversion - The
From
trait is the most flexible, useful for value and reference conversions
As a library author, you should prefer implementing From<T>
rather than
Into<U>
, as From
provides greater flexibility and offers an equivalent Into
implementation for free, thanks to a blanket implementation in the standard library.
Note: these traits must not fail. If the conversion can fail, you must use a dedicated
method which returns an Option<T>
or a Result<T, E>
.
Generic impl
AsRef
andAsMut
auto-dereference if the inner type is a referenceFrom<U> for T
impliesInto<T> for U
From
andInto
are reflexive, which means that all types caninto()
themselves andfrom()
themselves
See each trait for usage examples.
Traits
AsMut |
A cheap, mutable reference-to-mutable reference conversion. |
AsRef |
A cheap, reference-to-reference conversion. |
From |
Construct |
Into |
A conversion that consumes |