pub struct Takeable<T> { /* private fields */ }
Expand description
A wrapper-type that always holds a single T
value.
This type is implemented using an Option<T>
, however, the wrapper requires the Option<T>
to
always contain a value.
Panics
If the closure given to borrow
or borrow_result
panics, then the Takeable
is left in an
invalid 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. The object
will also be permanently invalidated if the value is moved out manually using take
.
It is always safe to drop the Takeable
even when invalidated.
Implementations
sourceimpl<T> Takeable<T>
impl<T> Takeable<T>
sourcepub fn new(value: T) -> Takeable<T>
pub fn new(value: T) -> Takeable<T>
Constructs a new Takeable<T>
value.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Takes ownership of the inner value.
sourcepub fn borrow<F>(&mut self, f: F)where
F: FnOnce(T) -> T,
pub fn borrow<F>(&mut self, f: F)where
F: FnOnce(T) -> T,
Updates the inner value using the provided closure.
sourcepub fn borrow_result<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(T) -> (T, R),
pub fn borrow_result<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(T) -> (T, R),
Updates the inner value using the provided closure, which also returns a result.
Trait Implementations
sourceimpl<T> From<T> for Takeable<T>
impl<T> From<T> for Takeable<T>
sourcefn from(value: T) -> Self
fn from(value: T) -> Self
Converts a T
value into a Takeable<T>
.
sourceimpl<T: Ord> Ord for Takeable<T>
impl<T: Ord> Ord for Takeable<T>
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl<T: PartialEq> PartialEq<Takeable<T>> for Takeable<T>
impl<T: PartialEq> PartialEq<Takeable<T>> for Takeable<T>
sourceimpl<T: PartialOrd> PartialOrd<Takeable<T>> for Takeable<T>
impl<T: PartialOrd> PartialOrd<Takeable<T>> for Takeable<T>
sourcefn partial_cmp(&self, other: &Takeable<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Takeable<T>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more