[−][src]Struct gstuff::Constructible
A cell that can be initialized, but only once.
Once initialized the cell remains immutable, allowing us to alias the value.
Methods
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]
F: Fn() -> &'a T,
T: 'a,
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]
T: Copy,
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]
T: Clone,
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> Default for Constructible<T>
[src]
Creates a cell without a value.
Use pin
or initialize
to provide the value later.
fn default() -> Constructible<T>
[src]
impl<T> Drop for Constructible<T>
[src]
impl<T> From<T> for Constructible<T>
[src]
Pre-initialize the cell with the given value.
fn from(v: T) -> Constructible<T>
[src]
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> Debug for Constructible<T> where
T: Debug,
[src]
T: Debug,
Debug formatting similar to Option<&T>
.
impl<T> Display for Constructible<T> where
T: Display,
[src]
T: Display,
Prints the value or "-" if it is not yet available.
impl<T, E> FromStr for Constructible<T> where
T: FromStr<Err = E>,
E: Display,
[src]
T: FromStr<Err = E>,
E: Display,
Allows to parse
directly into the cell.
Auto Trait Implementations
impl<T> Sync for Constructible<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Constructible<T> where
T: Unpin,
T: Unpin,
impl<T> Send for Constructible<T> where
T: Send,
T: Send,
impl<T> UnwindSafe for Constructible<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> !RefUnwindSafe for Constructible<T>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,