[][src]Enum core_extensions::void::Void

pub enum Void {}

Type for impossible situations.

Use this as a type parameter to enums to make the variants that use it unconstructible.

This type is used in ResultLike to unwrap values that can only be either the ok or error variants of the type.

Interaction with unsafe code

It is only valid to convert to Void from other Void-like types, it is undefined behavior to convert from any constructible type,even if zero-sized.

Example,infallible FromStr implementation.

use std::str::FromStr;
use core_extensions::{SelfOps,ResultLike,Void};

#[derive(Debug,PartialEq)]
pub struct Double(pub String);
impl FromStr for Double{
    type Err=Void;
    fn from_str(s:&str)->Result<Self,Void>{
        s.repeat(2)
            .piped(Double)
            .piped(Ok)
    }
}

assert_eq!(
    "12345".parse::<Double>().unwrap_safe(),
    Double("12345".repeat(2))
);

Example,infinite loop which only returns on error.

use core_extensions::{ResultLike,Void};

#[derive(Debug,PartialEq)]
enum Error<T>{
    InvalidItem(T),
    IteratorWasntInfinite,
}
fn reading_numbers<I>(i:I)->Result<Void,Error<usize>>
where I:IntoIterator<Item=usize>
{
    for elem in i{
        if elem==0 { return Err(Error::InvalidItem(elem)) }
        println!("{}",elem);
    }
    Err(Error::IteratorWasntInfinite)
}

assert_eq!(reading_numbers(1..100).unwrap_err_safe() , Error::IteratorWasntInfinite);
assert_eq!(reading_numbers(0..).unwrap_err_safe() , Error::InvalidItem(0));

Methods

impl Void[src]

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

Converts a Void to any type.

Note that because Void is impossible to construct, this method is unreachable.

Trait Implementations

impl Debug for Void[src]

impl Display for Void[src]

impl<T: ?Sized> PartialEq<T> for Void[src]

impl Eq for Void[src]

impl Ord for Void[src]

impl<T: ?Sized> PartialOrd<T> for Void[src]

impl Hash for Void[src]

impl Copy for Void[src]

impl Clone for Void[src]

impl Serialize for Void[src]

This impl is only enabled if the "serde_" feature is enabled.

impl<'de> Deserialize<'de> for Void[src]

This impl is only enabled if the "serde_" feature is enabled.

This always Returns an Err(D::Error::custom(DeserializeVoidError)).

Auto Trait Implementations

impl Unpin for Void

impl Send for Void

impl Sync for Void

impl UnwindSafe for Void

impl RefUnwindSafe for Void

Blanket Implementations

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

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

The error type returned when the conversion fails.

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

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

type Error = !

The type returned in the event of a conversion error.

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

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.

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[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> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]