Skip to main content

EventRing

Struct EventRing 

Source
pub struct EventRing<T> { /* private fields */ }
Expand description

A bounded, replayable buffer of stream events.

Generic over the payload because the ring is transport machinery: it must not name an MCP type, and a serde_json::Value in a domain signature is exactly the kind of raw JSON the layer rules keep out of here. The adapter supplies whatever its wire type is.

Implementations§

Source§

impl<T> EventRing<T>

Source

pub fn new(capacity: NonZeroUsize) -> Self

A ring retaining at most capacity events.

A capacity of zero is refused at the type level rather than tolerated: such a ring would accept a push, drop it, and report success, which is the eviction-as-success bug with no eviction to notice.

Retains RECOMMENDED_CAPACITY events.

Source

pub const fn capacity(&self) -> usize

The most events this ring will hold.

Source

pub const fn last(&self) -> EventId

The newest id ever issued, or the watermark if nothing has been.

Source

pub const fn len(&self) -> usize

How many events are currently retained.

Source

pub const fn is_empty(&self) -> bool

Whether nothing is retained.

Source

pub const fn evicted_through(&self) -> Option<EventId>

The newest event ever dropped, if the ring has dropped anything.

A client at or after this id can still be served contiguously; a client before it cannot.

Source

pub fn push(&mut self, payload: T) -> EventId

Appends an event, dropping the oldest if the ring is full.

Returns the id assigned, which is the value a client will quote to resume after this event.

Source

pub fn replay_from(&self, after: Option<EventId>) -> Replay<'_, T>

Answers a client that says where it stopped.

after is the client’s Last-Event-ID, or None for a client that has never seen this stream and wants everything. The four outcomes are described on Replay; the short version is that a request is only Replay::is_complete when the ring is still holding everything after the watermark.

Takes &self and hands back a borrow, so an adapter can answer from a shared reference without taking the stream’s lock exclusively.

Source

pub fn clear(&mut self)

Empties the ring, keeping the id sequence going.

A new stream, not a continuing one: ids stay monotonic so a client that reconnects across the reset is refused with Replay::Unknown rather than being served events from a stream that no longer exists.

Trait Implementations§

Source§

impl<T: Debug> Debug for EventRing<T>

Source§

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

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

impl<T> Default for EventRing<T>

Source§

fn default() -> Self

Retains RECOMMENDED_CAPACITY, so EventRing::default() is the unmeasured-payload case and never a zero-capacity ring.

Auto Trait Implementations§

§

impl<T> Freeze for EventRing<T>
where Vec<StreamEvent<T>>: Freeze,

§

impl<T> RefUnwindSafe for EventRing<T>

§

impl<T> Send for EventRing<T>
where Vec<StreamEvent<T>>: Send,

§

impl<T> Sync for EventRing<T>
where Vec<StreamEvent<T>>: Sync,

§

impl<T> Unpin for EventRing<T>
where Vec<StreamEvent<T>>: Unpin,

§

impl<T> UnsafeUnpin for EventRing<T>

§

impl<T> UnwindSafe for EventRing<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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