pub struct SharedOnceCell<T: Copy + 'static> { /* private fields */ }Implementations§
Sourcepub fn create(path: impl AsRef<Path>) -> Result<Self, SharedOnceError>
pub fn create(path: impl AsRef<Path>) -> Result<Self, SharedOnceError>
Obtain the cell at path, initializing an empty one if the path
does not yet exist and attaching to it if it does. Attaching
leaves an initialized value in place; a region built for a
different payload type is a LayoutMismatch.
reset reinitializes.
Sourcepub fn reset(path: impl AsRef<Path>) -> Result<Self, SharedOnceError>
pub fn reset(path: impl AsRef<Path>) -> Result<Self, SharedOnceError>
Truncate the cell at path and initialize an empty one,
discarding whatever value a live peer holds. For a caller that
knows it owns the path.
pub fn open(path: impl AsRef<Path>) -> Result<Self, SharedOnceError>
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
True when the cell has been initialised.
Sourcepub fn get(&self) -> Option<T>
pub fn get(&self) -> Option<T>
Get the value if initialised; otherwise return None. Non-blocking; never invokes the initialiser.
Sourcepub fn set(&self, value: T) -> bool
pub fn set(&self, value: T) -> bool
Try to write the value. Returns true if this caller won
the init race, false if the cell was already initialised
or another init is in progress.
Sourcepub fn get_or_init<F: FnOnce() -> T>(&self, init: F) -> T
pub fn get_or_init<F: FnOnce() -> T>(&self, init: F) -> T
Get the cached value, or run init to produce it. The first
caller across all processes runs init; subsequent callers
spin until the value is published and return that value.
Sourcepub fn flush_async(&self) -> Result<(), SharedOnceError>
pub fn flush_async(&self) -> Result<(), SharedOnceError>
Non-blocking flush: schedules a writeback via the OS. Note: Windows is only partially async (sync to page cache, not to disk).