pub struct LazySharedRing { /* private fields */ }Expand description
Defer the file-backed MMF setup until first use.
When to reach for this: speculative channel construction
where the consumer may or may not ever send/recv (per-connection
channels that some connections never use, conditional code paths,
option-types that hold a ring “just in case”). Construction is
free; the file create + ftruncate + mmap + init cost is paid
once on the first try_push or
try_pop call.
When NOT to reach for this: in-process-only one-shots
(use SharedRing::create_anon instead, which skips the file
entirely), or hot paths that always send (the lazy branch costs
one extra atomic load per op vs holding &SharedRing directly).
Hot-path tip: materialise once outside your loop and reuse
the returned &SharedRing reference so the lazy branch lives
outside the inner loop.
Implementations§
Sourcepub fn new(path: impl Into<PathBuf>, capacity: usize) -> Self
pub fn new(path: impl Into<PathBuf>, capacity: usize) -> Self
Construct a lazy ring. No syscalls; just stores the path and capacity for the deferred create.
Sourcepub fn get(&self) -> Result<&SharedRing, RingError>
pub fn get(&self) -> Result<&SharedRing, RingError>
Materialise the inner ring, paying the setup cost on the first call and returning the cached reference thereafter.
Sourcepub fn is_initialised(&self) -> bool
pub fn is_initialised(&self) -> bool
Whether the underlying ring has been materialised yet.