Skip to main content

ManagerCmd

Enum ManagerCmd 

Source
pub enum ManagerCmd<A: Actor> {
    SpawnActor {
        actor: A,
        id_tx: Option<Sender<usize>>,
    },
    StopActor(usize),
    Forward {
        id: usize,
        cmd: A::Cmd,
    },
}
Expand description

管理器的命令枚举。

通过 ActorHandle::send_cmd 发送给 ActorManager,控制子 actor 的生命周期和通信。

§变体

变体说明
ManagerCmd::SpawnActor启动一个新的子 actor,可以选择返回分配的 id(通过oneshot通道)
ManagerCmd::StopActor停止指定 id 的子 actor
ManagerCmd::Forward向指定 id 的子 actor 转发一条命令

§示例

let handle = ActorManager::<MyActor>::new().spawn();

// 启动子 actor
let (id_tx,id_rx) = tokio::sync::oneshot::channel();
handle.send_cmd(ManagerCmd::SpawnActor{actor:MyActor,id_tx:Some(id_tx)}).await.unwrap();
let id = id_rx.await.unwrap();
// 转发命令给 id=1 的子 actor
handle.send_cmd(ManagerCmd::Forward { id: 1, cmd: "hello".into() }).await.unwrap();

// 停止 id=1 的子 actor
handle.send_cmd(ManagerCmd::StopActor(1)).await.unwrap();

Variants§

§

SpawnActor

启动一个新的子 actor。

管理器会为其分配唯一 id,并通过 ManagerEvent::Spawned 事件通知。

Fields

§actor: A
§

StopActor(usize)

停止指定 id 的子 actor。

停止后通过 ManagerEvent::Stopped 事件通知。

§

Forward

向指定 id 的子 actor 转发一条命令。

若 id 不存在,命令会被静默丢弃。

Fields

§cmd: A::Cmd

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for ManagerCmd<A>

§

impl<A> !UnwindSafe for ManagerCmd<A>

§

impl<A> Freeze for ManagerCmd<A>
where A: Freeze, <A as Actor>::Cmd: Freeze,

§

impl<A> Send for ManagerCmd<A>
where <A as Actor>::Cmd: Send,

§

impl<A> Sync for ManagerCmd<A>
where A: Sync, <A as Actor>::Cmd: Sync,

§

impl<A> Unpin for ManagerCmd<A>
where A: Unpin, <A as Actor>::Cmd: Unpin,

§

impl<A> UnsafeUnpin for ManagerCmd<A>
where A: UnsafeUnpin, <A as Actor>::Cmd: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more