simpl_actor
simpl_actor
is a Rust library for simplifying actor-based concurrency in Rust applications. It is built on top of Tokio, utilizing async/await and tokio mpsc channels for efficient and intuitive actor system implementation.
Features
- Simple Actor Definition: Easily define actors with Rust structs and an attribute macro.
- Automatic Message Handling: Implement message handling with minimal code, leveraging Rust's type system and async capabilities.
- Asynchronous and Synchronous Messaging: Support for both asynchronous and synchronous message processing, allowing for flexible actor interaction patterns.
- Lifecycle Management: Lifecycle hooks for initializing, restarting, and stopping actors, providing control over the actor lifecycle.
Quick Start
Define an actor:
use ;
Interact with the actor:
let counter = new;
let actor = counter.spawn;
actor.inc.await?;
actor.dec.await?;
let count = actor.count.await?;
Messaging Variants
When you define a message in simpl_actor
, two variants of the message handling function are automatically for syncronous and asyncronous processing:
// Generates
The _after and _async variants are only generated if the method does not have any lifetimes.
In other words, all parameters must be owned or &'static
for the async variant to be generated,
otherwise the actor might reference deallocated memory causing UB.
Contributing
Contributions are welcome! Feel free to submit pull requests, create issues, or suggest improvements.
License
simpl_actor
is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
This means you can choose the license that best suits your project's needs.