pub struct ActorConfig { /* private fields */ }Expand description
Configuration parameters required to initialize a new actor.
This struct encapsulates the essential settings for creating an actor instance, including its unique identity, its relationship within the actor hierarchy (parent), and its connection to the system message broker.
The actor’s identity is represented by an Ern, which supports
hierarchical naming. If a parent actor is specified during configuration, the
final Ern of the new actor will be derived by appending its base id to the
parent’s Ern.
Implementations§
Source§impl ActorConfig
impl ActorConfig
Sourcepub fn new(
id: Ern,
parent: Option<ActorHandle>,
broker: Option<ActorHandle>,
) -> Result<Self>
pub fn new( id: Ern, parent: Option<ActorHandle>, broker: Option<ActorHandle>, ) -> Result<Self>
Creates a new ActorConfig instance, potentially deriving a hierarchical ID.
This constructor configures a new actor. If a parent handle is provided,
the actor’s final id (Ern) is constructed by appending the provided id
segment to the parent’s Ern. If no parent is provided, the id is used directly.
§Arguments
id- The base identifier (Ern) for the actor. IfparentisSome, this acts as the final segment appended to the parent’s ID. IfparentisNone, this becomes the actor’s root ID.parent- An optional [ParentRef] (handle) to the supervising actor.broker- An optional [BrokerRef] (handle) to the system message broker.
§Returns
Returns a Result containing the configured ActorConfig instance.
§Errors
Returns an error if parsing the parent’s ID string into an Ern fails when
constructing a hierarchical ID.
Sourcepub const fn with_inbox_capacity(self, capacity: usize) -> Self
pub const fn with_inbox_capacity(self, capacity: usize) -> Self
Sets a custom inbox capacity for this actor.
This allows overriding the global default inbox capacity on a per-actor basis. High-throughput actors may benefit from larger capacities, while low-throughput actors can use smaller capacities to conserve memory.
§Arguments
capacity- The inbox channel capacity for this actor.
§Returns
Returns self for method chaining.
Sourcepub const fn with_restart_policy(self, policy: RestartPolicy) -> Self
pub const fn with_restart_policy(self, policy: RestartPolicy) -> Self
Sets the restart policy for this actor when supervised.
The restart policy determines how the supervisor handles actor termination:
RestartPolicy::Permanent: Always restart (except during parent shutdown)RestartPolicy::Temporary: Never restartRestartPolicy::Transient: Restart only on abnormal termination (panic, inbox closed)
§Arguments
policy- The restart policy to use for this actor.
§Returns
Returns self for method chaining.
Sourcepub fn new_with_name(name: impl Into<String>) -> Result<Self>
pub fn new_with_name(name: impl Into<String>) -> Result<Self>
Creates a new ActorConfig for a top-level actor with a root identifier.
This is a convenience function for creating an ActorConfig for an actor
that has no parent (i.e., it’s a root actor in the hierarchy). The provided
name is used to create a root Ern.
§Arguments
name- A string-like value that will be used as the root name for the actor’sErn.
§Returns
Returns a Result containing the new ActorConfig instance with no parent or broker.
§Errors
Returns an error if creating the root Ern from the provided name fails
(e.g., if the name is invalid according to Ern rules).
Sourcepub const fn with_supervision_strategy(
self,
strategy: SupervisionStrategy,
) -> Self
pub const fn with_supervision_strategy( self, strategy: SupervisionStrategy, ) -> Self
Sets the supervision strategy for managing child actors.
The supervision strategy determines how the supervisor handles child terminations:
SupervisionStrategy::OneForOne: Restart only the failed childSupervisionStrategy::OneForAll: Restart all children when one failsSupervisionStrategy::RestForOne: Restart the failed child and all children started after it
§Arguments
strategy- The supervision strategy to use for this actor.
§Returns
Returns self for method chaining.
Sourcepub const fn with_restart_limiter(self, config: RestartLimiterConfig) -> Self
pub const fn with_restart_limiter(self, config: RestartLimiterConfig) -> Self
Sets the restart limiter configuration for this actor.
The restart limiter controls how frequently an actor can be restarted and applies exponential backoff between restart attempts:
- Tracks restarts within a sliding time window
- Limits the maximum number of restarts within that window
- Applies exponential backoff delays between restarts
When the restart limit is exceeded, the supervisor should escalate the failure to its parent rather than continuing to restart.
§Arguments
config- TheRestartLimiterConfigspecifying limits and backoff parameters.
§Returns
Returns self for method chaining.
Trait Implementations§
Source§impl Clone for ActorConfig
impl Clone for ActorConfig
Source§fn clone(&self) -> ActorConfig
fn clone(&self) -> ActorConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more