Core Concepts¶
1) Actor¶
Each actor implements the Actor trait.
type Message: message type this actor acceptstype Result: handler result typetype Error: handler error typehandle(&mut self, Arc<Self::Message>)
Each actor defines its own independent message type.
2) ActorSystem¶
ActorSystem manages actors by address (String).
- register:
register(...) - send:
send::<T>(address, msg) - request/response:
send_and_recv::<T>(address, msg) - broadcast:
send_broadcast::<T>(regex, msg) - job execution:
run_job::<T>(...)
3) Type-Safety Model¶
Compile-Time Guarantees¶
send::<T>() accepts <T as Actor>::Message.
Once T is chosen, the message type is fixed at compile time.
For example, send::<MyActor1>(..., MyMessage2::B(...)) does not compile.
Runtime Guarantees¶
Addresses are plain strings, so address-to-actor-type matching is validated at runtime.
- system stores
actor_typewith each address FindActorchecks type equality- mismatch returns runtime errors such as
AddressNotFoundorMessageTypeMismatch
In short:
- message type compatibility: compile time
- address mapping compatibility: runtime
4) Lifecycle and Failure Handling¶
Actor lifecycle states:
StartingReceivingStoppingTerminatedRestarting
On handler error, behavior depends on ErrorHandling:
Resume: continue actor loopRestart: restart actorStop: terminate actor