Crate tonari_actor[−][src]
This crate aims to provide a minimalist and high-performance actor framework for Rust with significantly less complexity than other frameworks like Actix.
In this framework, each Actor is its own OS-level thread. This makes debugging
noticeably simpler, and is suitably performant when the number of actors
is less than or equal to the number of CPU threads.
Example
use tonari_actor::{Actor, Context, System}; struct TestActor {} impl Actor for TestActor { type Error = (); type Message = usize; fn name() -> &'static str { "TestActor" } fn handle(&mut self, _context: &Context<Self>, message: Self::Message) -> Result<(), ()> { println!("message: {}", message); Ok(()) } } let mut system = System::new("default"); // will spin up a new thread running this actor let addr = system.spawn(TestActor {}).unwrap(); // send messages to actors to spin off work... addr.send(1usize).unwrap(); // ask the actors to finish and join the threads. system.shutdown().unwrap();
Structs
| Addr | |
| Context | An execution context for a specific actor. Specifically, this is useful for managing
the lifecycle of itself (through the |
| DisconnectedError | The actor message channel is disconnected. |
| Recipient | Similar to |
| SpawnBuilder | A builder for specifying how to spawn an |
| System | Systems are responsible for keeping track of their spawned actors, and managing their lifecycles appropriately. |
| SystemCallbacks | |
| SystemHandle | Contains the “metadata” of the system, including information about the registry of actors currently existing within the system. |
Enums
| ActorError | |
| Control | The set of available control messages that all actors respond to. |
| SendError | Reasons why sending a message to an actor can fail. |
Traits
| Actor | The base actor trait. |
| SendResultExt |