[][src]Struct gstuff::Constructible

pub struct Constructible<T> { /* fields omitted */ }

A cell that can be initialized, but only once.
Once initialized the cell remains immutable, allowing us to alias the value.

NB: There is a similar abstraction at https://github.com/matklad/once_cell. (I've only just discovered it, some months after implementing the Constructible myself).

Implementations

impl<T> Constructible<T>[src]

pub fn initialize<'a>(&'a self, v: Box<T>) -> Result<&'a T, String>[src]

Provides the cell with the value.
The value is effectively pinned in the cell, it won't be moved.
Returns an error if the cell is already initialized.

pub fn pin<'a>(&'a self, v: T) -> Result<&'a T, String>[src]

Provides the cell with the value.
The value is moved into a Box and pinned there.
Returns an error if the cell is already initialized.

pub fn or<'a, F>(&'a self, default: &'a F) -> &'a T where
    F: Fn() -> &'a T,
    T: 'a, 
[src]

Get a reference to the value.
If the value is not (yet) available then returns the reference provided by default.

pub fn copy_or(&self, default: T) -> T where
    T: Copy
[src]

Returns a copy of the value or the default if the value is not yet available.

pub fn clone_or(&self, default: T) -> T where
    T: Clone
[src]

Returns a clone of the value or the default if the value is not yet available.

pub fn ok_or<'a, E>(&'a self, error: E) -> Result<&'a T, E>[src]

Returns a reference to the value or the given error if the value is not yet available.

pub fn as_option<'a>(&'a self) -> Option<&'a T>[src]

Returns a reference to the value or None if the value is not yet available.

pub fn is_none(&self) -> bool[src]

True if the value is not yet available.

pub fn is_some(&self) -> bool[src]

True if the cell is now initialized with a value.

pub fn iter<'a>(&'a self) -> IntoIter<&'a T>[src]

Returns a reference to the value unless it was not yet initialized.

Trait Implementations

impl<T> Debug for Constructible<T> where
    T: Debug
[src]

Debug formatting similar to Option<&T>.

impl<T> Default for Constructible<T>[src]

Creates a cell without a value.
Use pin or initialize to provide the value later.

impl<T> Display for Constructible<T> where
    T: Display
[src]

Prints the value or "-" if it is not yet available.

impl<T> Drop for Constructible<T>[src]

impl<T> From<Option<T>> for Constructible<T>[src]

Translate an Option into a Constructible cell.
If the Option has a value then the cell with be initialized with it.
If the Option is empty then the cell will be empty as well, and waiting for delayed initialization.

impl<T> From<T> for Constructible<T>[src]

Pre-initialize the cell with the given value.

impl<T, E> FromStr for Constructible<T> where
    T: FromStr<Err = E>, 
[src]

Allows to parse directly into the cell.

type Err = E

The associated error which can be returned from parsing.

impl<'a, T> IntoIterator for &'a Constructible<T>[src]

Makes it possible to access the value with a for loop.

for value in &constructible {println! ("{}", value)}

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = IntoIter<&'a T>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<T> RefUnwindSafe for Constructible<T> where
    T: RefUnwindSafe

impl<T> Send for Constructible<T> where
    T: Send

impl<T> Sync for Constructible<T> where
    T: Sync

impl<T> Unpin for Constructible<T> where
    T: Unpin

impl<T> UnwindSafe for Constructible<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.