Skip to main content

LogRing

Struct LogRing 

Source
struct LogRing<const N: usize> {
    state: UnsafeCell<State<N>>,
}
Expand description

Single-producer/single-consumer byte ring with overwrite-oldest policy.

Every operation runs inside one critical section. Positions are logical usize cursors masked into the buffer (size must be a power of two), so wrap-around is just masking and dropping the oldest bytes never moves data.

Fields§

§state: UnsafeCell<State<N>>

Implementations§

Source§

impl<const N: usize> LogRing<N>

Source

const MASK: usize

Bitmask mapping a logical cursor to a buffer offset (N - 1).

Source

const fn new() -> Self

Create an empty ring; const fn so a static can build it.

Source

fn used(s: &State<N>) -> usize

Number of pending bytes (tail - head with wrapping arithmetic).

Source

fn push(&self, data: &[u8])

Append data, overwriting the oldest bytes when there is not enough room. Never panics, never allocates.

Source

fn peek(&self, out: &mut [u8]) -> usize

Copy up to out.len() pending bytes into out without consuming them. Returns how many were copied.

Source

fn commit(&self, n: usize)

Mark the n most recently peeked bytes as consumed. Values larger than the pending amount consume everything.

Source

fn drain_snapshot(&self, out: &mut [u8]) -> usize

Copy the newest bytes into out, then empty the ring. Returns how many bytes were written (oldest data is dropped first when out is too small).

Bytes before the floor marker are skipped: a snapshot must contain the panic banner plus the log lines that followed the boot-time replay, never the replayed report itself.

Source

fn set_floor(&self)

Mark the current write position as the earliest byte drain_snapshot may capture.

Trait Implementations§

Source§

impl<const N: usize> Sync for LogRing<N>

Auto Trait Implementations§

§

impl<const N: usize> !Freeze for LogRing<N>

§

impl<const N: usize> !RefUnwindSafe for LogRing<N>

§

impl<const N: usize> Send for LogRing<N>

§

impl<const N: usize> Unpin for LogRing<N>

§

impl<const N: usize> UnsafeUnpin for LogRing<N>

§

impl<const N: usize> UnwindSafe for LogRing<N>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.