pub enum ManagerEvent<Event> {
ChildEvent {
id: usize,
event: Event,
},
Spawned {
id: usize,
},
Stopped {
id: usize,
},
}Expand description
管理器发出的事件枚举。
聚合了所有子 actor 的事件以及管理器自身的生命周期事件。
通过 ActorHandle::get_events_rx 或 events_listen_async 订阅。
§变体
| 变体 | 说明 |
|---|---|
ManagerEvent::ChildEvent | 某个子 actor 发出的事件,附带其 id |
ManagerEvent::Spawned | 新子 actor 已启动,附带分配的 id |
ManagerEvent::Stopped | 子 actor 已停止,附带其 id |
§示例
let handle = ActorManager::<MyActor>::new().spawn();
let mut rx = handle.get_events_rx();
while let Ok(event) = rx.recv().await {
match event {
ManagerEvent::ChildEvent { id, event } => {
println!("actor {id} 发出事件: {event}");
}
ManagerEvent::Spawned { id } => {
println!("新 actor 已启动,id={id}");
}
ManagerEvent::Stopped { id } => {
println!("actor {id} 已停止");
}
}
}Variants§
Trait Implementations§
Source§impl<Event: Clone> Clone for ManagerEvent<Event>
impl<Event: Clone> Clone for ManagerEvent<Event>
Auto Trait Implementations§
impl<Event> Forget for ManagerEvent<Event>
impl<Event> Freeze for ManagerEvent<Event>where
Event: Freeze,
impl<Event> Move for ManagerEvent<Event>
impl<Event> RefUnwindSafe for ManagerEvent<Event>where
Event: RefUnwindSafe,
impl<Event> Send for ManagerEvent<Event>where
Event: Send,
impl<Event> Sync for ManagerEvent<Event>where
Event: Sync,
impl<Event> Unpin for ManagerEvent<Event>where
Event: Unpin,
impl<Event> UnsafeUnpin for ManagerEvent<Event>where
Event: UnsafeUnpin,
impl<Event> UnwindSafe for ManagerEvent<Event>where
Event: UnwindSafe,
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