pub struct HandlerRegistry { /* private fields */ }Expand description
处理器注册中心
按 task_type 注册 TaskHandler 实例及其 TaskConfig。
在应用启动时一次性完成注册,运行时只读访问。
Implementations§
Source§impl HandlerRegistry
impl HandlerRegistry
Sourcepub fn register(
&mut self,
handler: impl TaskHandler + 'static,
config: TaskConfig,
) -> &mut Self
pub fn register( &mut self, handler: impl TaskHandler + 'static, config: TaskConfig, ) -> &mut Self
注册一个处理器及其配置
Sourcepub fn from_discovered(&mut self) -> &mut Self
pub fn from_discovered(&mut self) -> &mut Self
从编译期自动发现的 handler 注册(配合 #[task_handler] 宏)
读取 TASK_HANDLERS 分布式切片中的所有条目并注册。
可安全调用多次(后续条目覆盖先前的同名 task_type)。
Sourcepub fn get(&self, task_type: i16) -> Option<(Arc<dyn TaskHandler>, &TaskConfig)>
pub fn get(&self, task_type: i16) -> Option<(Arc<dyn TaskHandler>, &TaskConfig)>
按 task_type 获取处理器和配置
Sourcepub fn task_types(&self) -> Vec<i16>
pub fn task_types(&self) -> Vec<i16>
获取所有已注册的 task_type
Sourcepub fn get_config(&self, task_type: i16) -> Option<&TaskConfig>
pub fn get_config(&self, task_type: i16) -> Option<&TaskConfig>
获取配置
Trait Implementations§
Source§impl Clone for HandlerRegistry
impl Clone for HandlerRegistry
Source§fn clone(&self) -> HandlerRegistry
fn clone(&self) -> HandlerRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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