Actify
Actify is a pre-1.0 crate used in production. The API may still change between minor versions.
Sharing (mutable) state across async tasks in Rust usually means juggling mutexes and channels, and a lot of boilerplate like hand-writen message enums. Actify gives you a typed, async actor model built on Tokio for any struct. Just add #[actify] to an impl block and call your methods through a clonable [Handle].
Installation
Benefits
By generating the boilerplate code for you, a few key benefits are provided:
- Async actor model built on Tokio and channels, which can keep arbitrary owned data types.
- Atomic access and mutation of underlying data through clonable handles.
- Typed arguments and return values on the methods from your actor, exposed through each handle.
- No need to manually define message structs or enums!
- Built-in methods like
get(),set(),set_if_changed(), andsubscribe()even without using the macro. - Automatic broadcasting of state changes to subscribers, with
#[skip_broadcast]and#[broadcast]controls. - Local synchronization through
Cache, withrecv,recv_newest, and non-blocking variants. - Rate-limited updates through
Throttlewith configurableFrequency. - Generic type parameters supported in both actor types and method arguments.
- Extension traits for common types:
Vec,Option,HashMap,HashSet.
Example
Consider the following example, in which you want to turn your custom Greeter into an actor:
use ;
async
Reactive Subscriptions
Actors broadcast state changes automatically. Subscribers and caches let you react to updates without polling:
use Handle;
async
For full API documentation, see docs.rs.