Build Status Build status Current Crates.io Version Document

may_actor

rust native actor library based on may

with this library * you don’t need to declare messages that passed into the actor * you don’t have to implement “actor” interface or trait for your actor. * the actors will automatically have M:N scheduling powered by may

Usage

```rust extern crate mayactor; use mayactor::Actor;

fn main() { struct HelloActor(u32); let a = Actor::new(HelloActor(0));

a.call(|me| {
    me.0 = 10;
    println!("hello world");
});
// the with would wait previous messages process done
a.with(|me| println!("actor value is {}", me.0));

} ```

for a detailed example, please see pi.rs

Features

You can send messages to the actor with the call API. It accepts a closure that has the &mut T as parameter, so that you can change it’s internal state. The closure would be send to a queue inside the actor, and the actor would execute the closure asynchronously by a coroutine that associate with it . This API would not block user’s execution and would return immediately. if panic happens in the closure, it will be caught and ignored in actor's coroutine context.

You can also synchronously manipulate the actor's internal state by the with API. It accepts a closure that has the &mut T as parameter, so that you can view or modify actor's internal state. The closure would be executed by the associated coroutine if there are no other pending messages. And it will block until the closure returns the result to caller. If any panic happens in the closure, it will propagate to the caller's context

You can transmute a &self type unsafely to it's handle type Actor<T>. This is convenient when need to get an actor handle in the implementation that need to pass as a function parameter.

However transmute from non actor context would trigger undefined behavior.

Notice

License

may_actor is licensed under either of the following, at your option: