lib.rs |
This crate provides a `LazyCell` struct which acts as a lazily filled
`Cell`.
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.
# 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. The limitation of an `AtomicLazyCell`
is that after it is initialized, it can't be modified. |
20451 |