Crate takeable

source ·
Expand description

Crate for temporarily or permanently moving out of a mutable pointer.

This crate implements a single wrapper-type Takeable<T>. The main purpose of this wrapper is that it provides two convenient helper functions Takeable::borrow and Takeable::borrow_result that allows for temporarily moving out of the wrapper without violating safety. The value can also be permanently moved out, invalidating the container and causing a panic on any future attempts to access the value.

The Takeable::borrow and Takeable::borrow_result methods work similarly to take from the take_mut crate. The main difference is that, while the take_mut is implemented using careful handling of unwind safety, this crate uses an Option<T> inside to make unwinding work as expected.

The Takeable::take method works similarly to Option::take, but has the advantage that the object becomes permanently invalidated. Additionally, using a Takeable<T> instead of an Option<T> makes it clear in code that a value is always expected and avoids the need to handle possible Option::None variants when accessing the T.


A wrapper-type that always holds a single T value.