Skip to main content

InputChain

Struct InputChain 

Source
pub struct InputChain<T: ?Sized> { /* private fields */ }
Expand description

Hooks ordered stably by (priority DESC, id ASC). Steady-state dispatch never allocates: an empty chain or non-matching event kind exits in O(1) via the cached Self::kinds_mask.

Implementations§

Source§

impl<T: ?Sized> InputChain<T>

Source

pub const fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub const fn kinds_mask(&self) -> InputKinds

Cached union of all registered slots’ InputKinds masks for O(1) batch pre-filtering.

Source

pub fn any_hook(&self, pred: impl FnMut(&T) -> bool) -> bool

Returns true when any registered slot satisfies pred (a hook currently executing through Self::run_shared counts as active).

Source

pub fn push(&mut self, kinds: InputKinds, hook: Box<T>) -> InputHookId

Registers hook for the event kinds in kinds at InputPriority::NORMAL.

Source

pub fn push_with_priority( &mut self, kinds: InputKinds, priority: InputPriority, hook: Box<T>, ) -> InputHookId

Registers hook for the event kinds in kinds at priority, maintaining stable (priority DESC, id ASC) order.

Source

pub fn remove(&mut self, id: InputHookId) -> Option<Option<Box<T>>>

Unregisters id. None when unknown; Some(None) while it runs through Self::run_shared (it drops once it returns). Callers holding a RefCell borrow drop the returned hook after releasing it.

Source

pub fn run( &mut self, ev: &ValidatedEvent<'_>, call: impl FnMut(&mut T) -> Disposition, ) -> Disposition

Runs call on each hook whose kinds contain ev’s interaction kind, in (priority DESC, id ASC) order, until one consumes it; returns that disposition (or Disposition::PassThrough).

Source

pub fn run_shared( cell: &RefCell<Self>, ev: &ValidatedEvent<'_>, call: impl FnMut(&mut T) -> Disposition, ) -> Disposition

Self::run without holding a borrow of cell while a hook runs, so hooks may register or remove hooks or dispatch again: a nested dispatch skips the hooks already running, hooks added after the current (priority DESC, id ASC) position run later in this pass, and a hook removed while it runs drops once it returns (outside any borrow).

Source§

impl<Cx: ?Sized> InputChain<dyn InputInterceptor<Cx>>

Source

pub fn has_active(&self) -> bool

Returns true when at least one registered interceptor reports InputInterceptor::is_active.

Source

pub fn intercept(&mut self, ev: &ValidatedEvent<'_>, cx: &mut Cx) -> Disposition

Runs the matching interceptors in order until one consumes ev.

Source

pub fn intercept_shared( cell: &RefCell<Self>, ev: &ValidatedEvent<'_>, cx: &mut Cx, ) -> Disposition

Self::intercept through a shared cell: interceptors may register, remove or dispatch again while they run (see InputChain::run_shared).

Source§

impl<Cx: ?Sized> InputChain<dyn DefaultAction<Cx>>

Source

pub fn run_default( &mut self, ev: &ValidatedEvent<'_>, cx: &mut Cx, ) -> Disposition

Runs the matching default actions in order until one consumes ev.

Source

pub fn run_default_shared( cell: &RefCell<Self>, ev: &ValidatedEvent<'_>, cx: &mut Cx, ) -> Disposition

Self::run_default through a shared cell (see InputChain::run_shared).

Trait Implementations§

Source§

impl<T: ?Sized> Default for InputChain<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Forget for InputChain<T>
where T: ?Sized,

§

impl<T> Freeze for InputChain<T>
where PhantomData<fn() -> InteractionEvent>: Freeze, *const u8 is !null: Freeze, PhantomData<Slot<T>>: Freeze, T: ?Sized,

§

impl<T> Move for InputChain<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for InputChain<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for InputChain<T>
where RawVecInner: Send, BoxRaw<T>: Send, T: ?Sized,

§

impl<T> Sync for InputChain<T>
where RawVecInner: Sync, BoxRaw<T>: Sync, T: ?Sized,

§

impl<T> Unpin for InputChain<T>
where *const u8 is !null: Unpin, Box<T>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for InputChain<T>

§

impl<T> UnwindSafe for InputChain<T>
where RawVecInner: UnwindSafe, BoxRaw<T>: UnwindSafe, T: ?Sized,

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 = !

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.