[−][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));
Implementations
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 Clone for Void
[src]
impl Copy for Void
[src]
impl Debug for Void
[src]
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>,
impl Display for Void
[src]
impl Eq for Void
[src]
impl Hash for Void
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Void
[src]
fn cmp(&self, _: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: ?Sized> PartialEq<T> for Void
[src]
impl<T: ?Sized> PartialOrd<T> for Void
[src]
fn partial_cmp(&self, _: &T) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for Void
[src]
This impl is only enabled if the "serde_" feature is enabled.
Auto Trait Implementations
impl RefUnwindSafe for Void
impl Send for Void
impl Sync for Void
impl Unpin for Void
impl UnwindSafe for Void
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> 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, U> TryInto<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,