pub struct CommandRouter<S = ()> { /* private fields */ }Expand description
声明式命令路由。每应用实例一份,不引入全局状态。
S = () 保持 0.6 的无状态用法;S != () 时处理器通过
CommandScope::app_state_mut 修改应用持有的类型化状态。
Implementations§
Source§impl<S> CommandRouter<S>
impl<S> CommandRouter<S>
pub fn new() -> Self
Sourcepub fn register<F>(&mut self, id: CommandId, handler: F) -> &mut Self
pub fn register<F>(&mut self, id: CommandId, handler: F) -> &mut Self
注册命令处理器;重复注册同一 ID 覆盖旧处理器(构建期行为)。
pub fn registered(&self) -> usize
pub fn stats(&self) -> CommandStats
Sourcepub fn dispatch(
&mut self,
scope: &mut CommandScope<'_, S>,
id: CommandId,
) -> CommandOutcome
pub fn dispatch( &mut self, scope: &mut CommandScope<'_, S>, id: CommandId, ) -> CommandOutcome
投递命令。未注册 ID 返回 PassThrough,计入 delivered/passthrough。
Trait Implementations§
Source§impl<S> Debug for CommandRouter<S>
impl<S> Debug for CommandRouter<S>
Auto Trait Implementations§
impl<S = ()> !RefUnwindSafe for CommandRouter<S>
impl<S = ()> !Send for CommandRouter<S>
impl<S = ()> !Sync for CommandRouter<S>
impl<S = ()> !UnwindSafe for CommandRouter<S>
impl<S> Forget for CommandRouter<S>
impl<S> Freeze for CommandRouter<S>
impl<S> Move for CommandRouter<S>
impl<S> Unpin for CommandRouter<S>
impl<S> UnsafeUnpin for CommandRouter<S>
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