Struct efficient_enum::option::EfficientOption
[−]
[src]
pub struct EfficientOption<A, B = (), TM = TagMSB>(_, _)
where
A: TaggableValue<TM, One>;
An option type similar to Option<(A, B)>
, but where no extra data is used. Instead, some of
the space in A
is used to "tag the union".
The one true downside is that it is impossible to get &A
from &EfficientOption
. The reason
for this is that doing so would expose the private tag info.
Methods
impl<TM, A, B> EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
fn new(a: Option<(A, B)>) -> Self
Constructs a new EfficientOption
fn new_0(a: Option<A>) -> Self where
B: Default,
B: Default,
Constructs a new EfficientOption
fn new_1(b: Option<B>) -> Self where
A: Default,
A: Default,
Constructs a new EfficientOption
fn none() -> Self
Constructs an empty EfficientOption
fn some((a, b): (A, B)) -> Self
Constructs an EfficientOption
from an A
value
fn some_0(a: A) -> Self where
B: Default,
B: Default,
Constructs an EfficientOption
from an A
value
fn some_1(b: B) -> Self where
A: Default,
A: Default,
Constructs an EfficientOption
from an B
value
fn clone_0(&self) -> Option<A> where
A: Clone,
A: Clone,
Clones the A
value if one exists
fn clone_1(&self) -> Option<B> where
B: Clone,
B: Clone,
Clones the B
value if one exists
fn as_ref(&self) -> Option<(&A, &B)>
Gets references to both the A
and B
values if they exist
fn ref_0(&self) -> Option<&A>
Gets a reference to the A
value if one exists
fn ref_1(&self) -> Option<&B>
Gets a reference to the B
value if one exists
unsafe fn unwrap_ref(&self) -> (&A, &B)
Gets references to both the A
and B
values by assuming they exist
unsafe fn unwrap_ref_0(&self) -> &A
Gets a reference to the A
value by assuming one exists
unsafe fn unwrap_ref_1(&self) -> &B
Gets a reference to the A
value by assuming one exists
fn as_mut(&mut self) -> Option<(&A, &mut B)>
Gets a reference to the A
value and a mutable reference to the B
value if they exist
fn mut_1(&mut self) -> Option<&mut B>
Gets mutable a reference to the B
value if one exists
unsafe fn unwrap_as_mut(&mut self) -> (&A, &mut B)
Gets a reference to the A
value and a mutable reference to the B
value by assuming they exist
unsafe fn unwrap_mut_1(&mut self) -> &mut B
Gets mutable a reference to the B
value by assuming one exists
fn inner(&mut self) -> EfficientOptionInner<A, B, TM>
Returns an EfficientOptionInnerSome
if the option is a Some
value, returns an
EfficientOptionInnerNone
otherwise.
unsafe fn inner_some(&mut self) -> EfficientOptionInnerSome<A, B, TM>
Returns an EfficientOptionInnerSome
.
unsafe fn inner_none(&mut self) -> EfficientOptionInnerNone<A, B, TM>
Returns an EfficientOptionInnerSome
.
fn destructure(self) -> Option<(A, B)>
Destructures an EfficientOption
fn destructure_0(self) -> Option<A>
Destructures an EfficientOption
into the A
value if one exists
fn destructure_1(self) -> Option<B>
Destructures an EfficientOption
into the B
value if one exists
unsafe fn unwrap_destructure(self) -> (A, B)
Destructures an EfficientOption
unsafe fn unwrap_destructure_0(self) -> A
Destructures an EfficientOption
into the A
value by assuming one exists
unsafe fn unwrap_destructure_1(self) -> B
Destructures an EfficientOption
into the B
value by assuming one exists
fn take(&mut self) -> Option<(A, B)>
Takes the value out of the option, leaving a None in its place.
fn take_0(&mut self) -> Option<A>
Takes both values out of the option, leaving a None in its place.
The version only returns the A
value
fn take_1(&mut self) -> Option<B>
Takes both values out of the option, leaving a None in its place.
The version only returns the B
value
fn is_some(&self) -> bool
Returns true
if the option is a Some
value.
fn is_none(&self) -> bool
Returns true
if the option is a None
value.
fn map<R, F>(&mut self, f: F) -> R where
F: FnOnce(Option<(&mut A, &mut B)>) -> R,
F: FnOnce(Option<(&mut A, &mut B)>) -> R,
Maps the value to a result
Trait Implementations
impl<TM, A: Clone, B: Clone> Clone for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<TM, A: Copy, B: Copy> Copy for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A, B> Default for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A: Debug, B: Debug> Debug for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A: PartialEq, B: PartialEq> PartialEq for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Self) -> bool
This method tests for !=
.
impl<TM, A: Eq, B: Eq> Eq for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A: Hash, B: Hash> Hash for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<TM, A> From<Option<A>> for EfficientOption<A, (), TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A, B> From<Option<(A, B)>> for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A, B> Into<Option<(A, B)>> for EfficientOption<A, B, TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,
impl<TM, A> Into<Option<A>> for EfficientOption<A, (), TM> where
A: TaggableValue<TM, One>,
[src]
A: TaggableValue<TM, One>,