1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crateActorError;
use async_trait;
use ;
use Debug;
/// Defines the core logic for state transitions, actions, and guards within an actor.
///
/// This trait encapsulates the behavior of a state machine. It determines how the actor
/// moves between states and updates its context based on incoming events.
///
/// Typically, the `create_machine` macro (planned for Phase 2) will automatically generate
/// a struct implementing this trait based on a declarative state machine definition.
/// Manual implementation is possible but the macro approach is generally preferred for
/// consistency and reduced boilerplate.
// --- Example Dummy Implementation ---
/*
struct MyMachineLogic;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
enum MyState { Idle, Processing }
#[async_trait]
impl ActorLogic for MyMachineLogic {
type Context = i32;
type Event = String;
type State = MyState;
fn initial(&self) -> (Self::State, Self::Context) {
(MyState::Idle, 0)
}
async fn transition(&self, state: Self::State, context: Self::Context, event: Self::Event)
-> Result<(Self::State, Self::Context), ActorError>
{
println!("Transitioning from {:?} with context {} on event \"{}\"", state, context, event);
match (state, event.as_str()) {
(MyState::Idle, "START") => Ok((MyState::Processing, context + 1)),
(MyState::Processing, "STOP") => Ok((MyState::Idle, context)),
(s, _) => Ok((s, context)), // No change for other events
}
}
}
*/