16 unstable releases (4 breaking)

0.5.1 Nov 5, 2024
0.4.2 May 17, 2024
0.3.3 Mar 14, 2024
0.3.0 Dec 28, 2023
0.2.0 Jul 31, 2023

#158 in Concurrency

Download history 22/week @ 2024-08-17 8/week @ 2024-08-24 27/week @ 2024-08-31 63/week @ 2024-09-07 132/week @ 2024-09-14 140/week @ 2024-09-21 122/week @ 2024-09-28 322/week @ 2024-10-05 161/week @ 2024-10-12 29/week @ 2024-10-19 56/week @ 2024-10-26 228/week @ 2024-11-02 54/week @ 2024-11-09 52/week @ 2024-11-16 60/week @ 2024-11-23 66/week @ 2024-11-30

251 downloads per month
Used in rust-cutil

MIT license

61KB
1K SLoC

Actify

Note that this crate is under construction. Although used in production, work is done on making an intuitive API, documententation and remaining features. For the time being, this does not follow semantic versioning!

Actify is an actor model built on Tokio that allows annotating any regular implementation block of your own type with the actify! macro.

Crates.io License Docs

Benefits

By generating the boilerplate code for you, a few key benefits are provided:

  • Async actor model build 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!
  • Generic methods like get() and set() even without using the macro.

Example

Consider the following example, in which you want to turn your custom Greeter into an actor:

use actify::{Handle, actify};

#[derive(Clone, std::fmt::Debug)]
struct Greeter {}

#[actify]
impl Greeter {
    fn say_hi(&self, name: String) -> String {
        format!("hi {}", name)
    }
}

#[tokio::main]
async fn main() {
// An actify handle is created and initialized with the Greeter struct
let handle = Handle::new(Greeter {});

// The say_hi method is made available on its handle through the actify! macro
let greeting = handle.say_hi("Alfred".to_string()).await.unwrap();

// The method is executed remotely on the initialized Greeter and returned through the handle
assert_eq!(greeting, "hi Alfred".to_string())
}

Dependencies

~3.5–9.5MB
~90K SLoC