[][src]Enum never::Never

pub enum Never {}

A type that can never be constructed.

Never can never be constructed (in type theory parlance, it is "uninhabited"). It represents any computation which never resolves to a particular value (because it runs forever, panics, aborts the process, etc). Because the Never type can never be constructed, the existence of a Never proves that a piece of code can never be reached.

For example, we could write a function like:

fn result_into_ok<T>(res: Result<T, Never>) -> T {
    match res {
        Ok(t) => t,
        // This branch can never be taken, and so the
        // compiler is happy to treat it as evaluating
        // to whatever type we wish - in this case, `T`.
        Err(never) => match never {},
    }
}

Generalizing, it is always valid to convert a Never into a value of any other type. We provide the into_any and to_any methods for this purpose.

Never is a stable version of the currently-unstable ! type from the standard library.

Methods

impl Never[src]

pub fn into_any<T>(self) -> T[src]

Convert this Never into a value of a different type.

Since a Never can never be constructed, this is valid for any Sized type.

pub fn to_any<T>(&self) -> T[src]

Convert this Never into a value of a different type.

Since a Never can never be constructed, this is valid for any Sized type.

Trait Implementations

impl<T: ?Sized> AsMut<T> for Never[src]

impl<T: ?Sized> AsRef<T> for Never[src]

impl BufRead for Never[src]

impl Clone for Never[src]

impl Copy for Never[src]

impl Debug for Never[src]

impl Display for Never[src]

impl Eq for Never[src]

impl Error for Never[src]

impl Hash for Never[src]

impl Ord for Never[src]

impl PartialEq<Never> for Never[src]

impl PartialOrd<Never> for Never[src]

impl Read for Never[src]

impl Seek for Never[src]

impl StructuralEq for Never[src]

impl StructuralPartialEq for Never[src]

impl Write for Never[src]

Auto Trait Implementations

impl RefUnwindSafe for Never

impl Send for Never

impl Sync for Never

impl Unpin for Never

impl UnwindSafe for Never

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.