agner_actors/
actor.rs

1use std::future::Future;
2
3use crate::context::Context;
4use crate::exit::Exit;
5
6/// A marker trait for actor behaviour function.
7///
8/// It is recommended to rely on the existing implementation of this trait for certain
9/// async-functions, rather than implementing this trait manually.
10pub trait Actor<'a, A, M>: Send + 'static {
11    type Out: Into<Exit>;
12    type Fut: Future<Output = Self::Out> + Send + 'a;
13
14    fn run(self, context: &'a mut Context<M>, args: A) -> Self::Fut;
15}
16
17impl<'a, A, M, F, Fut, Out> Actor<'a, A, M> for F
18where
19    M: 'a,
20    F: FnOnce(&'a mut Context<M>, A) -> Fut,
21    Fut: Future<Output = Out> + 'a,
22    Fut: Send,
23    Out: Into<Exit>,
24    F: Send + 'static,
25{
26    type Out = Out;
27    type Fut = Fut;
28
29    fn run(self, context: &'a mut Context<M>, args: A) -> Self::Fut {
30        self(context, args)
31    }
32}