Struct takeable::Takeable

source ·
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

Constructs a new Takeable<T> value.

Takes ownership of the inner value.

Updates the inner value using the provided closure.

Updates the inner value using the provided closure, which also returns a result.

Moves out the inner value and invalidates the object.

Subsequent calls to any methods except is_usable will panic, including attempts to deference the object.

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, or if the value is explicitly moved out permanently with take.

Trait Implementations

Gets a mutable reference to the underlying value.

Gets a reference to the underlying value.

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more

Converts a T value into a Takeable<T>.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.