[−][src]Enum core_extensions::void::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 Eq for Void
[src]
impl Copy for Void
[src]
impl<T: ?Sized> PartialOrd<T> for Void
[src]
fn partial_cmp(&self, _: &T) -> Option<Ordering>
[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]
fn eq(&self, _: &T) -> bool
[src]
#[must_use]
default fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for Void
[src]
fn clone(&self) -> Void
[src]
default fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Ord for Void
[src]
fn cmp(&self, _: &Self) -> Ordering
[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]
clamp
)Restrict a value to a certain interval. Read more
impl Debug for Void
[src]
impl Hash for Void
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
default fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Display 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))
.
fn deserialize<D>(_: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Auto Trait Implementations
Blanket Implementations
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The error type returned when the conversion fails.
fn try_into(Self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,