1.0.0[][src]Module core::convert

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.

As a library author, you should prefer implementing From<T> or TryFrom<T> rather than Into<U> or TryInto<U>, as From and TryFrom provide greater flexibility and offer equivalent Into or TryInto implementations for free, thanks to a blanket implementation in the standard library. However, there are some cases where this is not possible, such as creating conversions into a type defined outside your library, so implementing Into instead of From is sometimes necessary.

Generic Implementations

See each trait for usage examples.



A cheap, mutable reference-to-mutable reference conversion.


A cheap reference-to-reference conversion. Used to convert a value to a reference value within generic code.


Simple and safe type conversions in to Self. It is the reciprocal of Into.


A conversion that consumes self, which may or may not be expensive. The reciprocal of From.


Attempt to construct Self via a conversion.


An attempted conversion that consumes self, which may or may not be expensive.



An identity function.