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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/// Cala program control flow loop.
pub enum Loop<T> {
/// Exit the program.
///
/// # Usage
/// ```
/// // Set the home loop to `do_nothing()`.
/// cala::init!(do_nothing, ());
///
/// // This program just quits right away.
/// pub fn do_nothing(_: &mut ()) -> cala::Loop<()> {
/// // Exit.
/// cala::Exit
/// }
/// ```
Exit,
/// Keep the program running.
///
/// # Usage
/// ```
/// // Set the home loop to `infinite_loop()`.
/// cala::init!(infinite_loop, ());
///
/// // This program runs until the user interupts it.
/// pub fn infinite_loop(_: &mut ()) -> cala::Loop<()> {
/// // Run this function again.
/// cala::Continue
/// }
/// ```
Continue,
/// Go back one activity.
///
/// # Usage
/// ```
/// // Set the home loop to `home()`.
/// cala::init!(home, ());
///
/// // This program creates 2 new activities, which both go back right away.
/// pub fn home(_: &mut ()) -> cala::Loop<()> {
/// // `activity_a` is first, because it will be on the top of the activity stack.
/// cala::ReplaceWithBack(activity_a, activity_b)
/// }
///
/// pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
/// println!("First");
/// // Go to activity_b
/// cala::Back
/// }
///
/// pub fn activity_b(_: &mut ()) -> cala::Loop<()> {
/// println!("Last");
/// // Quit
/// cala::Back
/// }
/// ```
Back,
/// Add new activities to the activity stack (new activity loop).
///
/// # Usage
/// ```
/// // Set the home loop to `home()`.
/// cala::init!(home, ());
///
/// // Infinite loop.
/// pub fn home(_: &mut ()) -> cala::Loop<()> {
/// // `activity_a` is first, because it will be on the top of the activity stack.
/// cala::Append(activity_a)
/// }
///
/// pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
/// // Go to activity `home()`
/// cala::Back
/// }
/// ```
Append(fn(&mut T) -> Loop<T>),
/// Add a new activity to the activity stack (new activity loop), throwing away the
/// one on top (the current activity).
///
/// # Usage
/// ```
/// // Set the home loop to `home()`.
/// cala::init!(home, ());
///
/// // This program creates 1 new activity, which quits right away.
/// pub fn home(_: &mut ()) -> cala::Loop<()> {
/// // Replace our `home()` activity with `activity_a()`.
/// cala::Replace(activity_a)
/// }
///
/// pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
/// // Quit
/// cala::Exit
/// }
/// ```
Replace(fn(&mut T) -> Loop<T>),
/// Add 2 new activities to the activity stack (new activity loop), throwing away the
/// one on top (the current activity). First parameter is the activity that the user
/// will enter, and the second is the one they will enter when they go back.
///
/// # Usage
/// ```
/// // Set the home loop to `home()`.
/// cala::init!(home, ());
///
/// // This program creates 2 new activities, which both go back right away.
/// pub fn home(_: &mut ()) -> cala::Loop<()> {
/// // `activity_a` is first, because it will be on the top of the activity stack.
/// cala::ReplaceWithBack(activity_a, activity_b)
/// }
///
/// pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
/// println!("First");
/// // Go to activity_b
/// cala::Back
/// }
///
/// pub fn activity_b(_: &mut ()) -> cala::Loop<()> {
/// println!("Last");
/// // Quit
/// cala::Back
/// }
/// ```
ReplaceWithBack(fn(&mut T) -> Loop<T>, fn(&mut T) -> Loop<T>),
}