Skip to main content

Ring

Struct Ring 

Source
pub struct Ring { /* private fields */ }
Expand description

A fixed-capacity, fleet-wide append-only log keyed on KIND byte.

V0 is single-process; V1 is SHM-backed. The API is the same.

Implementations§

Source§

impl Ring

Source

pub fn new<T: OrbitTyped>(capacity: usize) -> Self

Create a ring for type T with capacity slots.

Source

pub fn kind(&self) -> u8

The KIND byte this ring carries (equals T::KIND).

Source

pub fn capacity(&self) -> usize

Total slot count — fixed at construction.

Source

pub fn head(&self) -> u64

Monotonic head — number of writes ever performed. Slot index of the most recent write is (head() - 1) % capacity once head() > 0.

Source

pub fn write( &self, node_id: NodeId, frame_kind: u8, ver: u64, payload: Bytes, ) -> NetId64

Append a frame. Atomically reserves the next counter, mints the NetId64, and writes the frame into the corresponding slot. Returns the minted id.

frame_kind is the message class byte (V0: pass 0). ver is the version / tick at write time (V0: caller’s choice).

Source

pub fn read(&self, id: NetId64) -> Option<Frame>

Read the slot that the given NetId64’s counter points at.

Returns:

  • Some(frame) if the slot’s stored id matches the queried id exactly (the slot has not been overwritten by a later writer).
  • None if the slot is empty, has wrapped past, or holds a different id than the one asked for.
Source

pub fn read_head(&self) -> Option<Frame>

Read the most recent frame, regardless of who wrote it. Useful for “what’s the current state?” — ignores counter-by-counter walking.

Source

pub fn read_at(&self, counter: u64) -> Option<Frame>

Read whatever frame currently occupies the slot at counter % capacity, regardless of which counter is stored in it. Used by walking readers that need slot-by-slot access without knowing the writer’s NetId64 ahead of time.

Returns None if the slot is empty.

Source

pub fn reset(&self)

Clear all slots and reset the write head to zero.

Intended for owner-controlled boot-time cleanup. Do not call while other threads are publishing to this ring.

Trait Implementations§

Source§

impl Debug for Ring

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl RingFrameSource for Ring

Source§

fn kind(&self) -> u8

The OrbitTyped::KIND carried by this ring.
Source§

fn head(&self) -> u64

Monotonic write head: number of writes ever published.
Source§

fn capacity(&self) -> usize

Fixed slot count for this ring.
Source§

fn read_at(&self, counter: u64) -> Option<Frame>

Read the frame currently occupying counter % capacity.

Auto Trait Implementations§

§

impl !Freeze for Ring

§

impl RefUnwindSafe for Ring

§

impl Send for Ring

§

impl Sync for Ring

§

impl Unpin for Ring

§

impl UnsafeUnpin for Ring

§

impl UnwindSafe for Ring

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more