1use crate::actor::Address;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct User<A, M> {
8 pub from: A,
9 pub message: M,
10}
11
12pub trait EventInput<Input>: Sized {
18 fn inject(input: Input) -> Self;
19}
20
21pub trait RouteInput<Input>: Sized {
27 fn route(input: Input) -> Result<Self, Input>;
32}
33
34impl<A, M> EventInput<User<A, M>> for User<A, M> {
35 fn inject(input: User<A, M>) -> Self {
36 input
37 }
38}
39
40impl<A, M, Input> RouteInput<Input> for User<A, M> {
41 fn route(input: Input) -> Result<Self, Input> {
42 Err(input)
43 }
44}
45
46impl<A, M> User<A, M> {
47 #[must_use]
48 pub const fn new(from: A, message: M) -> Self {
49 Self { from, message }
50 }
51}
52
53impl<A, M> From<(A, M)> for User<A, M> {
54 fn from((from, message): (A, M)) -> Self {
55 Self::new(from, message)
56 }
57}
58
59pub trait UserEvent: Sized {
61 type Addr: Address;
62 type Message;
63
64 fn user(from: Self::Addr, message: Self::Message) -> Self;
65
66 fn into_user(self) -> Result<User<Self::Addr, Self::Message>, Self>;
69}
70
71impl<A: Address, M> UserEvent for User<A, M> {
72 type Addr = A;
73 type Message = M;
74
75 fn user(from: A, message: M) -> Self {
76 Self::new(from, message)
77 }
78 fn into_user(self) -> Result<Self, Self> {
79 Ok(self)
80 }
81}