pub enum Probably<T> {
Nothing,
Something(T),
}
Variants§
Implementations§
source§impl<T> Probably<T>
impl<T> Probably<T>
sourcepub const fn is_nothing(&self) -> bool
pub const fn is_nothing(&self) -> bool
Returns true
if self
is of variant Nothing
.
sourcepub const fn is_something(&self) -> bool
pub const fn is_something(&self) -> bool
Returns true
if self
is of variant Something
.
sourcepub fn as_something(&self) -> Option<&T>
pub fn as_something(&self) -> Option<&T>
Returns Some
if self
is a reference of variant Something
, and None
otherwise.
sourcepub fn as_mut_something(&mut self) -> Option<&mut T>
pub fn as_mut_something(&mut self) -> Option<&mut T>
Returns Some
if self
is a mutable reference of variant Something
, and None
otherwise.
sourcepub fn expect_something(self) -> Twhere
Self: Debug,
pub fn expect_something(self) -> Twhere
Self: Debug,
source§impl<T> Probably<Probably<T>>
impl<T> Probably<Probably<T>>
sourcepub fn flatten(self) -> Probably<T>
pub fn flatten(self) -> Probably<T>
Converts from Probably<Probably<T>>
to Probably<T>
.
Examples
Basic usage:
let x: Probably<Probably<u32>> = Something(Something(6));
assert_eq!(Something(6), x.flatten());
let x: Probably<Probably<u32>> = Something(Nothing);
assert_eq!(Nothing, x.flatten());
let x: Probably<Probably<u32>> = Nothing;
assert_eq!(Nothing, x.flatten());
Flattening only removes one level of nesting at a time:
let x: Probably<Probably<Probably<u32>>> = Something(Something(Something(6)));
assert_eq!(Something(Something(6)), x.flatten());
assert_eq!(Something(6), x.flatten().flatten());
Trait Implementations§
source§impl<T> FromResidual for Probably<T>
impl<T> FromResidual for Probably<T>
source§fn from_residual(residual: Probably<Infallible>) -> Self
fn from_residual(residual: Probably<Infallible>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
)Constructs the type from a compatible
Residual
type. Read moresource§impl<T: Ord> Ord for Probably<T>
impl<T: Ord> Ord for Probably<T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T: PartialEq> PartialEq for Probably<T>
impl<T: PartialEq> PartialEq for Probably<T>
source§impl<T: PartialOrd> PartialOrd for Probably<T>
impl<T: PartialOrd> PartialOrd for Probably<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T> Termination for Probably<T>
impl<T> Termination for Probably<T>
source§impl<T> Try for Probably<T>
impl<T> Try for Probably<T>
§type Output = T
type Output = T
🔬This is a nightly-only experimental API. (
try_trait_v2
)The type of the value produced by
?
when not short-circuiting.§type Residual = Probably<Infallible>
type Residual = Probably<Infallible>
🔬This is a nightly-only experimental API. (
try_trait_v2
)The type of the value passed to
FromResidual::from_residual
as part of ?
when short-circuiting. Read moresource§fn from_output(output: Self::Output) -> Self
fn from_output(output: Self::Output) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
)Constructs the type from its
Output
type. Read moresource§fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
🔬This is a nightly-only experimental API. (
try_trait_v2
)Used in
?
to decide whether the operator should produce a value
(because this returned ControlFlow::Continue
)
or propagate a value back to the caller
(because this returned ControlFlow::Break
). Read moreimpl<T: Copy> Copy for Probably<T>
impl<T: Eq> Eq for Probably<T>
impl<T> StructuralEq for Probably<T>
impl<T> StructuralPartialEq for Probably<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Probably<T>where
T: RefUnwindSafe,
impl<T> Send for Probably<T>where
T: Send,
impl<T> Sync for Probably<T>where
T: Sync,
impl<T> Unpin for Probably<T>where
T: Unpin,
impl<T> UnwindSafe for Probably<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more