Skip to main content

ave_actors_actor/
into_actor.rs

1//! Traits for converting values into actor instances, with compile-time enforcement of persistence rules.
2
3use crate::actor::{Actor, Handler};
4
5/// Marker trait for actors that do not use persistence.
6///
7/// Implement this on your actor to allow passing it directly to
8/// `create_root_actor` or `create_child`. Persistent actors use
9/// `PersistentActor::initial()` instead and must NOT also implement this trait.
10pub trait NotPersistentActor {}
11
12/// Converts a value into an actor instance ready for the actor system.
13///
14/// Implemented automatically for [`NotPersistentActor`] types (identity conversion),
15/// and by the store crate for `InitializedActor<A>` (persistent actors).
16pub trait IntoActor<A: Actor + Handler<A>> {
17    fn into_actor(self) -> A;
18}
19
20impl<A: Actor + Handler<A> + NotPersistentActor> IntoActor<A> for A {
21    fn into_actor(self) -> A {
22        self
23    }
24}