From and Into
Implement `From<U> for T` and you automatically get `Into<T> for U` via a blanket impl. The convention is to implement `From`, then call sites use `T::from(u)` or `u.into()`. From should never fail — for fallible conversion use TryFrom.
TryFrom and TryInto
`TryFrom<U> for T` defines a fallible conversion returning `Result<T, Self::Error>`. The blanket impl gives you `TryInto<T> for U`. Use them for narrowing conversions (`u32 -> u16`), parse-like operations, and validations.
For deeper background, see a complete cheat-sheet of std collection complexities for the broader context behind this section.
AsRef and AsMut
`AsRef<T>` lets a type be cheaply borrowed as a `&T`. `&str` implements `AsRef<str>`; `String` implements `AsRef<str>`; `PathBuf` implements `AsRef<Path>`. Take `impl AsRef<Path>` in function parameters to accept any path-like input — `&str`, `String`, `&Path`, `PathBuf` — without intermediate conversion.
identity and infallible
`std::convert::identity(x)` returns x — sometimes useful as a default value for a higher-order function or to make a closure type-check. `std::convert::Infallible` is the never-failing error type, often used as the Error parameter for an infallible TryFrom impl, and `Result<T, Infallible>` can be safely unwrapped (or pattern-matched without an Err arm in stable Rust).
For deeper background, see the official Rust API guidelines for module-level design for the broader context behind this section.
When to reach for parse instead
`str::parse::<T>()` calls `T::from_str` — for string parsing it's usually the right tool, not TryFrom. Implement `FromStr` on your type to plug in. For non-string sources, use TryFrom.