Enum std::convert::Infallible
1.34.0 · source · [−]pub enum Infallible {}Expand description
The error type for errors that can never happen.
Since this enum has no variant, 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`
}
}RunFuture compatibility
This enum has the same role as the ! “never” type,
which is unstable in this version of Rust.
When ! is stabilized, we plan to make Infallible a type alias to it:
pub type Infallible = !;Run… and eventually deprecate Infallible.
However there is one case where ! syntax can be used
before ! is stabilized as a full-fledged type: in the position of a function’s return type.
Specifically, it is possible to have implementations for two different function pointer types:
trait MyTrait {}
impl MyTrait for fn() -> ! {}
impl MyTrait for fn() -> std::convert::Infallible {}RunWith Infallible being an enum, this code is valid.
However when Infallible becomes an alias for the never type,
the two impls will start to overlap
and therefore will be disallowed by the language’s trait coherence rules.
Trait Implementations
impl Clone for Infallible
const: unstable · source
impl Clone for Infallible
const: unstable · sourcefn clone(&self) -> Infallible
const: unstable · source
fn clone(&self) -> Infallible
const: unstable · sourceReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0 · source
fn clone_from(&mut self, source: &Self)
1.0.0 · sourcePerforms copy-assignment from source. Read more
impl Debug for Infallible
source
impl Debug for Infallible
sourceimpl Display for Infallible
source
impl Display for Infallible
sourceimpl Error for Infallible
1.8.0 · source
impl Error for Infallible
1.8.0 · sourcefn description(&self) -> &str
source
fn description(&self) -> &str
sourceuse the Display impl or to_string()
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0 · source
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0 · sourceThe lower-level source of this error, if any. Read more
impl From<!> for Infallible
const: unstable · source
impl From<!> for Infallible
const: unstable · sourcefn from(x: !) -> Infallible
const: unstable · source
fn from(x: !) -> Infallible
const: unstable · sourceConverts to this type from the input type.
impl From<Infallible> for TryFromIntError
const: unstable · source
impl From<Infallible> for TryFromIntError
const: unstable · sourcefn from(x: Infallible) -> TryFromIntError
const: unstable · source
fn from(x: Infallible) -> TryFromIntError
const: unstable · sourceConverts to this type from the input type.
impl From<Infallible> for TryFromSliceError
1.36.0 (const: unstable) · source
impl From<Infallible> for TryFromSliceError
1.36.0 (const: unstable) · sourcefn from(x: Infallible) -> TryFromSliceError
const: unstable · source
fn from(x: Infallible) -> TryFromSliceError
const: unstable · sourceConverts to this type from the input type.
impl Hash for Infallible
1.44.0 · source
impl Hash for Infallible
1.44.0 · sourceimpl Ord for Infallible
source
impl Ord for Infallible
sourceimpl PartialEq<Infallible> for Infallible
source
impl PartialEq<Infallible> for Infallible
sourceimpl PartialOrd<Infallible> for Infallible
source
impl PartialOrd<Infallible> for Infallible
sourcefn partial_cmp(&self, _other: &Infallible) -> Option<Ordering>
source
fn partial_cmp(&self, _other: &Infallible) -> Option<Ordering>
sourceThis method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0 · source
fn lt(&self, other: &Rhs) -> bool
1.0.0 · sourceThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0 · source
fn le(&self, other: &Rhs) -> bool
1.0.0 · sourceThis method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Copy for Infallible
sourceimpl Eq for Infallible
sourceAuto Trait Implementations
impl RefUnwindSafe for Infallible
impl Send for Infallible
impl Sync for Infallible
impl Unpin for Infallible
impl UnwindSafe for Infallible
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
source
impl<T> BorrowMut<T> for T where
T: ?Sized,
sourcefn borrow_mut(&mut self) -> &mut T
const: unstable · source
fn borrow_mut(&mut self) -> &mut T
const: unstable · sourceMutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
source
impl<T> ToOwned for T where
T: Clone,
sourcetype Owned = T
type Owned = T
The resulting type after obtaining ownership.
fn clone_into(&self, target: &mut T)
source
fn clone_into(&self, target: &mut T)
sourceUses borrowed data to replace owned data, usually by cloning. Read more