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>
impl<T: ?Sized> InputChain<T>
pub const fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub const fn kinds_mask(&self) -> InputKinds
pub const fn kinds_mask(&self) -> InputKinds
Cached union of all registered slots’ InputKinds masks for O(1) batch pre-filtering.
Sourcepub fn any_hook(&self, pred: impl FnMut(&T) -> bool) -> bool
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).
Sourcepub fn push(&mut self, kinds: InputKinds, hook: Box<T>) -> InputHookId
pub fn push(&mut self, kinds: InputKinds, hook: Box<T>) -> InputHookId
Registers hook for the event kinds in kinds at InputPriority::NORMAL.
Sourcepub fn push_with_priority(
&mut self,
kinds: InputKinds,
priority: InputPriority,
hook: Box<T>,
) -> InputHookId
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.
Sourcepub fn remove(&mut self, id: InputHookId) -> Option<Option<Box<T>>>
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.
Sourcepub fn run(
&mut self,
ev: &ValidatedEvent<'_>,
call: impl FnMut(&mut T) -> Disposition,
) -> Disposition
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).
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>>
impl<Cx: ?Sized> InputChain<dyn InputInterceptor<Cx>>
Sourcepub fn has_active(&self) -> bool
pub fn has_active(&self) -> bool
Returns true when at least one registered interceptor reports InputInterceptor::is_active.
Sourcepub fn intercept(&mut self, ev: &ValidatedEvent<'_>, cx: &mut Cx) -> Disposition
pub fn intercept(&mut self, ev: &ValidatedEvent<'_>, cx: &mut Cx) -> Disposition
Runs the matching interceptors in order until one consumes ev.
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>>
impl<Cx: ?Sized> InputChain<dyn DefaultAction<Cx>>
Sourcepub fn run_default(
&mut self,
ev: &ValidatedEvent<'_>,
cx: &mut Cx,
) -> Disposition
pub fn run_default( &mut self, ev: &ValidatedEvent<'_>, cx: &mut Cx, ) -> Disposition
Runs the matching default actions in order until one consumes ev.
Self::run_default through a shared cell (see InputChain::run_shared).