-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path07-state-data.rs
More file actions
42 lines (34 loc) · 977 Bytes
/
07-state-data.rs
File metadata and controls
42 lines (34 loc) · 977 Bytes
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
use statum::{machine, state, transition};
#[state]
enum State {
//NOTE: we add a state data to the Draft state
Draft(MyDraft),
InReview,
Published,
}
struct MyDraft {
_title: String,
_content: String,
}
#[machine]
struct Machine<State> {}
#[transition]
impl Machine<Draft> {
pub fn _into_in_review(self) -> Machine<InReview> {
//NOTE: we can access the state's data with &self.state_data
let my_draft_data_ref: &MyDraft = &self.state_data;
println!(
"This is us doing something with the reference to the draft data: {}",
my_draft_data_ref._title
);
self.transition()
}
}
pub fn run() {
let my_draft = MyDraft {
_title: "My first article".to_owned(),
_content: "This is the content of my first article".to_owned(),
};
//NOTE: we build the machine with the state data
let _machine = Machine::<Draft>::builder().state_data(my_draft).build();
}