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§
Source§impl<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) -> R
pub fn borrow_result<F, R>(&mut self, f: F) -> R
Updates the inner value using the provided closure, which also returns a result.
Trait Implementations§
Source§impl<T> From<T> for Takeable<T>
impl<T> From<T> for Takeable<T>
Source§fn from(value: T) -> Self
fn from(value: T) -> Self
Converts a T value into a Takeable<T>.