core::convert - Rust
Description: API documentation for the Rust `convert` mod in crate `core`.
Keywords: rust, rustlang, rust-lang, convert

# 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.

- Implement the `As*` traits for reference-to-reference conversions
- Implement 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
- The `TryFrom` and `TryInto` traits behave like `From` and `Into`, 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.

# Generic Implementations

- `AsRef` and `AsMut` auto-dereference if the inner type is a reference
- `From``<U> for T` implies `Into``<T> for U`
- `TryFrom``<U> for T` implies `TryInto``<T> for U`
- `From` and `Into` are reflexive, which means that all types can `into` themselves and `from` themselves

See each trait for usage examples.

## 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 `Self`. It is the reciprocal of `Into`.
Into | A conversion that consumes `self`, which may or may not be expensive. The reciprocal of `From`.
TryFrom | [ Experimental ] Attempt to construct `Self` via a conversion.
TryInto | [ Experimental ] An attempted conversion that consumes `self`, which may or may not be expensive.

## Functions

identity | [ Experimental ] An identity function.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)