Skip to main content

GuardStore

Struct GuardStore 

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

Type-erased per-(buffer, mode) Guard storage.

One per App, and in practice always behind a GuardStoreHandle (the registry’s activation / deactivation methods take the handle, so the spawned lifecycle task can insert into the same store). Default is empty.

Not Clone – Box<dyn Any> is not Clone.

M-async.4 epoch counter: each (buffer, mode) key carries a u64 epoch that monotonically increments on every activate begin + every deactivate. The dispatcher’s spawn task captures the epoch when it queues, then validates against the current epoch via Self::try_insert before stashing its Guard. A mismatch means a deactivate (or a later activate) arrived while the spawn was in flight; the returned Err(stale_guard) lets the spawn drop the Guard (firing its Drop for out-of-band cleanup) instead of stashing it in a logically-inactive store slot.

Implementations§

Source§

impl GuardStore

Source

pub fn new() -> Self

Empty store.

Source

pub fn insert( &mut self, buffer: BufferId, mode: ModeId, guard: Box<dyn Any + Send>, )

Stash a Guard for the given (buffer, mode). Replaces any existing entry (the old Guard is dropped, firing its Drop impl). Used in tests + the rare reload path; the production dispatcher routes through Self::try_insert to respect the epoch invariant.

Source

pub fn bump_epoch(&mut self, buffer: BufferId, mode: ModeId) -> u64

Bump the epoch for (buffer, mode) and return the new value. The dispatcher’s sync prefix calls this when queueing a step; the spawn task captures the returned value and passes it to Self::try_insert on completion. Wraps on overflow (u64::MAX → 0); the dispatcher tolerates this because consecutive bumps always advance by 1, so a wrap that happens to land on a stale spawn’s captured epoch would require 2^64 activate / deactivate cycles in flight – not a realistic concern.

Source

pub fn current_epoch(&self, buffer: BufferId, mode: ModeId) -> u64

Current epoch for (buffer, mode). 0 if the pair has never had an activation queued. Used by tests + the dispatcher’s spawn task to validate before stashing.

Source

pub fn try_insert( &mut self, buffer: BufferId, mode: ModeId, my_epoch: u64, guard: Box<dyn Any + Send>, ) -> Result<(), Box<dyn Any + Send>>

Insert guard only if my_epoch still matches the store’s current epoch for (buffer, mode). Returns Ok(()) on success; on epoch mismatch returns Err(guard) so the caller can drop the Guard outside the lock (the Box’s Drop then fires the original type’s cleanup).

Used by the M-async.4 spawn-task path: a deactivate (or a subsequent activate) arriving while a spawn was in flight bumps the epoch via Self::remove / Self::bump_epoch; the spawn’s late try_insert then fails the match and drops the Guard instead of stashing it in a logically-inactive store slot.

Source

pub fn remove( &mut self, buffer: BufferId, mode: ModeId, ) -> Option<Box<dyn Any + Send>>

Take ownership of the Guard for (buffer, mode), bumping the epoch so any in-flight spawn that hasn’t inserted yet fails its Self::try_insert check. Returns None if no Guard was stashed.

Source

pub fn purge_buffer(&mut self, buffer: BufferId)

Drop every Guard belonging to buffer. Call when a buffer is deleted – the dispatcher’s normal deactivation path may not run if the buffer vanishes before the App can deactivate its modes. Bumps the epoch for every (buffer, *) entry so any in-flight spawn for the purged buffer fails its later Self::try_insert.

Source

pub fn len(&self) -> usize

Number of stashed Guards.

Source

pub fn is_empty(&self) -> bool

True when no Guard is stashed.

Source

pub fn contains(&self, buffer: BufferId, mode: ModeId) -> bool

True iff a Guard is stashed for (buffer, mode).

Trait Implementations§

Source§

impl Debug for GuardStore

Source§

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

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

impl Default for GuardStore

Source§

fn default() -> GuardStore

Returns the “default value” for a type. Read more

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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