Skip to main content

SpawnBuilder

Struct SpawnBuilder 

Source
pub struct SpawnBuilder<'a, Parent, Child, W = NoWatch>
where Parent: Actor, Child: Actor,
{ /* private fields */ }
Expand description

Builder for configuring and spawning a child Actor. Created via Ctx::actor.

Implementations§

Source§

impl<'a, Parent, Child, W> SpawnBuilder<'a, Parent, Child, W>
where Parent: Actor, Child: Actor, W: OnErrTerminate<Child::Err>,

Source

pub fn supervision(self, supervision: Supervision) -> Self

Sets the Supervision strategy the parent will use for this child. Defaults to Supervision::Restart with unlimited restarts and no backoff.

§Example
ctx.actor::<Worker>(props)
    .supervision(Supervision::Restart {
        max: Limit::Amount(3),
        backoff: Backoff::Static(Duration::from_secs(1)),
    })
    .spawn();
Source

pub fn watch<F>( self, f: F, ) -> SpawnBuilder<'a, Parent, Child, WatchFn<F, Parent::Msg>>
where F: Fn(&Child::Err) -> Parent::Msg + Send + 'static,

Registers a callback that fires when the child terminates due to an error. This happens when the supervision strategy is Supervision::Stop, or when Supervision::Restart has exhausted all allowed restarts. The callback maps the child’s error into a message for the parent.

§Example
ctx.actor::<Worker>(props)
    .supervision(Supervision::Restart {
        max: Limit::Amount(3),
        backoff: Backoff::None,
    })
    .watch(|err| ParentMsg::WorkerDied(format!("{err:?}")))
    .spawn();
Source

pub fn spawn(self) -> Handle<Child::Msg>

Spawns the child Actor and returns a Handle to it.

Source

pub fn spawn_registered(self) -> Result<Handle<Child::Msg>, RegistryError>

Spawns the child and registers it in the global registry under its type name. Other actors can then look it up via Ctx::get_handle_for or Ctx::send. Returns RegistryError::NameTaken if already registered.

Source

pub fn spawn_named( self, name: impl Into<String>, ) -> Result<Handle<Child::Msg>, RegistryError>

Spawns the child and registers it in the global registry under the given name. Other actors can then look it up via Ctx::get_handle or Ctx::send_to. Returns RegistryError::NameTaken if the name is already taken.

§Example
let h = ctx.actor::<Worker>(props).spawn_named("worker-1")?;

Auto Trait Implementations§

§

impl<'a, Parent, Child, W> Freeze for SpawnBuilder<'a, Parent, Child, W>
where <Child as Actor>::Props: Freeze, W: Freeze,

§

impl<'a, Parent, Child, W> RefUnwindSafe for SpawnBuilder<'a, Parent, Child, W>
where <Child as Actor>::Props: RefUnwindSafe, W: RefUnwindSafe, <Parent as Actor>::Props: RefUnwindSafe,

§

impl<'a, Parent, Child, W> Send for SpawnBuilder<'a, Parent, Child, W>
where W: Send,

§

impl<'a, Parent, Child, W> Sync for SpawnBuilder<'a, Parent, Child, W>
where <Child as Actor>::Props: Sync, W: Sync, <Parent as Actor>::Props: Sync,

§

impl<'a, Parent, Child, W> Unpin for SpawnBuilder<'a, Parent, Child, W>
where <Child as Actor>::Props: Unpin, W: Unpin,

§

impl<'a, Parent, Child, W> UnsafeUnpin for SpawnBuilder<'a, Parent, Child, W>
where <Child as Actor>::Props: UnsafeUnpin, W: UnsafeUnpin,

§

impl<'a, Parent, Child, W = NoWatch> !UnwindSafe for SpawnBuilder<'a, Parent, Child, W>

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.