1.0.0[−][src]Module std::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.
- Implement the As*traits for reference-to-reference conversions
- Implement the Intotrait when you want to consume the value in the conversion
- The Fromtrait is the most flexible, useful for value and reference conversions
- The TryFromandTryIntotraits behave likeFromandInto, but allow for the conversion to fail
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
- AsRefand- AsMutauto-dereference if the inner type is a reference
- From- <U> for Timplies- Into- <T> for U
- TryFrom- <U> for Timplies- TryInto- <T> for U
- Fromand- Intoare reflexive, which means that all types can- intothemselves and- fromthemselves
See each trait for usage examples.
Enums
| Infallible | The error type for errors that can never happen. | 
Traits
| AsMut | A cheap, mutable reference-to-mutable reference conversion. | 
| AsRef | A cheap reference-to-reference conversion. Used to convert a value to a reference value within generic code. | 
| From | Simple and safe type conversions in to  | 
| Into | A conversion that consumes  | 
| TryFrom | Simple and safe type conversions that may fail in a controlled
way under some circumstances. It is the reciprocal of  | 
| TryInto | An attempted conversion that consumes  | 
Functions
| identity | An identity function. |