pub struct ActorBuilder<A: Actor> { /* private fields */ }
Expand description

Builder for Addr and Mailbox. This is a convenience API so you don’t have to call their constructors manually. Mainly lets you set the channel and name for your mailbox.

Also provides methods for spawning the mailbox immediately as well as a build method which lets you do it manually.

Implementations

Create a new ActorBuilder with default settings.

Configure a name for this actor. This will be helpful for interpreting debug logs. You can also retrieve the name later on both the Addr and the Mailbox.

Choose the bounded size of the default channel. If unset, will default to a bounded channel with a buffer size of 16. Note that thespis messages are boxed, so the buffer is only the size of 16 fat pointers. It still means consuming the actual heap storage if you count on the channel backpressure to keep your memory consumption down.

If you set this to None, you will get an unbounded channel.

This option is incompatible with manually providing a channel. Only works for the default channel.

Panics

In debug mode this will panic if you have already called ActorBuilder::channel.

Set the channel to use for communication between Addr and Mailbox.

This option is incompatible with bounded.

Panics

In debug mode this will panic if you have already called ActorBuilder::bounded.

Build Addr and Mailbox. This does not yet consume an actor and you have to call start or start_local on Mailbox and spawn the future to run your actor.

The advantage of this method is that you can pass the Addr to the constructor of your actor if you need to. Otherwise it’s advised to use ActorBuilder::spawn_handle or ActorBuilder::spawn_handle_local for convenience.

Spawn the mailbox on the provided executor. Returns Addr. Note that this detaches the mailbox on spawning. That means the actor will keep running until all Addr to it have been dropped.

If you want more control over stopping the actor, look at ActorBuilder::spawn_handle or ActorBuilder::build.

Spawn the mailbox on the provided executor. Returns Addr and a JoinHandle to the spawned mailbox.

Note that if you drop the JoinHandle it will stop the actor and drop it unless you call JoinHandle::detach on it.

The JoinHandle returns:

  • MailboxEnd::Mailbox if you actor panicked whilst processing a message. This way you can instantiate a new actor and spawn the mailbox again. This can be used for supervision. All existing addresses will remain valid when this happens.
  • MailboxEnd::Actor when the mailbox ends naturally. You can create a new mailbox and spawn the actor again if you want to re-use it.

For Actor: !Send. Spawn the mailbox on the provided executor. Returns the Addr.

If you want more control over stopping the actor, look at ActorBuilder::spawn_handle_local or ActorBuilder::build.

For Actor: !Send. Spawn the mailbox on the provided executor. Returns Addr and a JoinHandle to the spawned mailbox.

Note that if you drop the JoinHandle it will stop the actor and drop it unless you call JoinHandle::detach on it.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

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

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

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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

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

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