pub type Infallible = !;Expand description
The error type for errors that can never happen.
Since this is an alias to the never type, a value of this type can never actually exist.
This can be useful for generic APIs that use Result and parameterize the error type,
to indicate that the result is always Ok.
For example, the TryFrom trait (conversion that returns a Result)
has a blanket implementation for all types where a reverse Into implementation exists.
â
impl<T, U> TryFrom<U> for T where U: Into<T> {
type Error = Infallible;
fn try_from(value: U) -> Result<Self, Infallible> {
Ok(U::into(value)) // Never returns `Err`
}
}Note: since CURRENT_RUSTC_VERSION this is an alias to !. If targeting that or future versions,
prefer using the never type directly.