Struct gstuff::Constructible [−][src]
pub struct Constructible<T> { /* fields omitted */ }
Expand description
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
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.
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.
Get a reference to the value.
If the value is not (yet) available then returns the reference provided by default
.
Returns a copy of the value or the default
if the value is not yet available.
Returns a clone of the value or the default
if the value is not yet available.
Returns a reference to the value or the given error
if the value is not yet available.
Returns a reference to the value or None
if the value is not yet available.
Trait Implementations
Debug formatting similar to Option<&T>
.
Creates a cell without a value.
Use pin
or initialize
to provide the value later.
Returns the “default value” for a type. Read more
Prints the value or “-” if it is not yet available.
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.
Performs the conversion.
Pre-initialize the cell with the given value.
Performs the conversion.
Allows to parse
directly into the cell.
Makes it possible to access the value with a for
loop.
for value in &constructible {println! ("{}", value)}