Crate lazycell [] [src]

This crate provides a LazyCell struct which acts as a lazily filled Cell, but with frozen contents.

With a RefCell, the inner contents cannot be borrowed for the lifetime of the entire object, but only of the borrows returned. A LazyCell is a variation on RefCell which allows borrows to be tied to the lifetime of the outer object.

The limitation of a LazyCell is that after it is initialized and shared, it can be modified.

Example

The following example shows a quick example of the basic functionality of LazyCell.

use lazycell::LazyCell;

let lazycell = LazyCell::new();

assert_eq!(lazycell.borrow(), None);
assert!(!lazycell.filled());
lazycell.fill(1).ok();
assert!(lazycell.filled());
assert_eq!(lazycell.borrow(), Some(&1));
assert_eq!(lazycell.into_inner(), Some(1));

AtomicLazyCell is a variant that uses an atomic variable to manage coordination in a thread-safe fashion.

Structs

AtomicLazyCell

A lazily filled Cell, with frozen contents.

LazyCell

A lazily filled Cell, with frozen contents.