Skip to main content

LazySharedRing

Struct LazySharedRing 

Source
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§

Source§

impl LazySharedRing

Source

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.

Source

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.

Source

pub fn is_initialised(&self) -> bool

Whether the underlying ring has been materialised yet.

Source

pub fn try_push(&self, payload: &[u8]) -> Result<(), RingError>

Forwarded SharedRing::try_push; materialises on first call.

Source

pub fn try_pop(&self, out: &mut [u8]) -> Result<usize, RingError>

Forwarded SharedRing::try_pop; materialises on first call.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.