pub struct HandlerRegistry { /* private fields */ }Expand description
handler 注册管理器。线程安全。(含不透明函数对象,不 derive Debug)
Implementations§
Source§impl HandlerRegistry
impl HandlerRegistry
Sourcepub fn register(&self, event_type: impl Into<String>, f: HandlerFn) -> HandlerId
pub fn register(&self, event_type: impl Into<String>, f: HandlerFn) -> HandlerId
注册 handler 至指定 event_type,返回全局唯一 HandlerId 供注销。
注意:每次注册都会新增一条(闭包不可比较,原版“函数相等去重“无法复刻);
防重复注册由调用方负责,引擎只保证 id 唯一且可精确注销。
Sourcepub fn unregister(&self, id: HandlerId) -> bool
pub fn unregister(&self, id: HandlerId) -> bool
注销 HandlerId,无论挂在哪个 type 下;true 表示确实注销了某个。
类型列表变空时自动从表中移除该 type(对齐原版 pop(type))。
Sourcepub fn register_general(&self, f: HandlerFn) -> HandlerId
pub fn register_general(&self, f: HandlerFn) -> HandlerId
注册通用 handler;成功返回 HandlerId。
Sourcepub fn unregister_general(&self, id: HandlerId) -> bool
pub fn unregister_general(&self, id: HandlerId) -> bool
注销通用 handler。
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for HandlerRegistry
impl RefUnwindSafe for HandlerRegistry
impl Send for HandlerRegistry
impl Sync for HandlerRegistry
impl Unpin for HandlerRegistry
impl UnsafeUnpin for HandlerRegistry
impl UnwindSafe for HandlerRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more