Struct takeable::Takeable
[−]
[src]
pub struct Takeable<T> { /* fields omitted */ }
A wrapper-type that always holds a single T
value.
This type is implemented using an Option<T>
, however outside of the borrow_result
function,
this Option
will always contain a value.
Panics
If the closure given to borrow
or borrow_result
panics, then the Takeable
is left in an
unusable state without holding a T
. Calling any method on the object besides is_usable
when
in this state will result in a panic. This includes trying to dereference the object.
It is still safe to drop the value.
Methods
impl<T> Takeable<T>
[src]
fn new(value: T) -> Takeable<T>
Constructs a new Takeable<T>
value.
fn as_ref(&self) -> &T
Gets a reference to the inner value.
fn as_mut(&mut self) -> &mut T
Gets a mutable reference to the inner value.
fn into_inner(self) -> T
Takes ownership of the inner value.
fn borrow<F>(&mut self, f: F) where
F: FnOnce(T) -> T,
F: FnOnce(T) -> T,
Updates the inner value using the provided closure.
fn borrow_result<F, R>(&mut self, f: F) -> R where
F: FnOnce(T) -> (T, R),
F: FnOnce(T) -> (T, R),
Updates the inner value using the provided closure while also returns a result.
fn is_usable(&self) -> bool
Check if the object is still usable.
The object will always start out as usable, and can only enter an unusable state if the
methods borrow
or borrow_result
are called with closures that panic.
Trait Implementations
impl<T: Clone> Clone for Takeable<T>
[src]
fn clone(&self) -> Takeable<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Copy> Copy for Takeable<T>
[src]
impl<T: Debug> Debug for Takeable<T>
[src]
impl<T: Eq> Eq for Takeable<T>
[src]
impl<T: PartialEq> PartialEq for Takeable<T>
[src]
fn eq(&self, __arg_0: &Takeable<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Takeable<T>) -> bool
This method tests for !=
.
impl<T: Ord> Ord for Takeable<T>
[src]
fn cmp(&self, __arg_0: &Takeable<T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more
impl<T: PartialOrd> PartialOrd for Takeable<T>
[src]
fn partial_cmp(&self, __arg_0: &Takeable<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Takeable<T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Takeable<T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Takeable<T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Takeable<T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: Hash> Hash for Takeable<T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
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<T: Default> Default for Takeable<T>
[src]
impl<T> Deref for Takeable<T>
[src]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T> DerefMut for Takeable<T>
[src]
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value