[][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 Copy for Void[src]

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

#[must_use]
default fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
default fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
default fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
default fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

#[must_use]
default fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Eq for Void[src]

impl Ord for Void[src]

default fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

default fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

default fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl Clone for Void[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Hash for Void[src]

default fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Display for Void[src]

impl Debug 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 Send for Void

impl Sync for Void

Blanket Implementations

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

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

The error type returned when the conversion fails.

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

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]