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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//! Effect Trait - Core effect type definition
//!
//! > *"Effectus sequitur causam"*
//! > — The effect follows the cause. (Scholastic axiom)
use Debug;
/// Marker trait for effect types.
///
/// `Effectus` marks types that represent computational effects, such as
/// IO operations, state manipulation, error handling, or async operations.
///
/// Effects are not executed directly; instead, they are interpreted by
/// effect handlers ([`EffectusHandler`](super::EffectusHandler) or
/// [`EffectusHandlerAsync`](super::EffectusHandlerAsync)).
///
/// # Laws
///
/// Effect types should be:
/// 1. **Pure descriptions** - An effect value describes an action, not executes it
/// 2. **Composable** - Effects can be combined into larger effect descriptions
/// 3. **Interpretable** - Effects have at least one valid interpretation (handler)
///
/// # Implementing Effectus
///
/// Most effect types are simple marker types:
///
/// ```rust
/// use ordofp_core::effects::Effectus;
///
/// /// Custom logging effect
/// pub struct LogEffectus;
/// impl Effectus for LogEffectus {}
///
/// /// Parameterized database effect
/// pub struct DatabaseEffectus<C> {
/// _phantom: std::marker::PhantomData<C>,
/// }
/// impl<C: Send + Sync + 'static> Effectus for DatabaseEffectus<C> {}
/// ```
///
/// # Example
///
/// ```rust
/// use ordofp_core::effects::{Effectus, IoEffectus};
///
/// fn requires_io<E: Effectus>() {
/// // Function that works with any effect type
/// }
///
/// requires_io::<IoEffectus>();
/// ```
/// A trait for effects that carry a value.
///
/// Some effects need to carry data, such as a log message for a logging effect
/// or a query for a database effect.
///
/// # Example
///
/// ```rust
/// use ordofp_core::effects::{Effectus, EffectusWithValue};
///
/// pub enum LogLevel {
/// Info,
/// Warn,
/// Error,
/// }
///
/// pub struct LogEffect {
/// pub message: String,
/// pub level: LogLevel,
/// }
///
/// impl Effectus for LogEffect {}
///
/// impl EffectusWithValue for LogEffect {
/// type Value = String;
///
/// fn value(&self) -> &Self::Value {
/// &self.message
/// }
/// }
///
/// let effect = LogEffect { message: "hello".to_string(), level: LogLevel::Info };
/// assert_eq!(effect.value(), "hello");
/// ```
/// A trait for effects that can produce a result type.
///
/// This is used for effects that, when handled, produce a specific result type.
///
/// # Example
///
/// ```rust
/// use ordofp_core::effects::{Effectus, EffectusProduces};
///
/// pub struct ReadFileEffect {
/// pub path: String,
/// }
///
/// impl Effectus for ReadFileEffect {}
///
/// impl EffectusProduces for ReadFileEffect {
/// type Result = Result<String, std::io::Error>;
/// }
/// ```
/// Trait for effect types that can be combined.
///
/// This allows composing multiple effects into a single effect type.
///
/// # Example
///
/// ```rust
/// use ordofp_core::effects::{CombinedEffectus, Effectus, EffectusCombine};
///
/// struct MyIoEffectus;
/// impl Effectus for MyIoEffectus {}
///
/// struct MyErrorEffectus;
/// impl Effectus for MyErrorEffectus {}
///
/// impl EffectusCombine<MyErrorEffectus> for MyIoEffectus {
/// type Combined = CombinedEffectus<MyIoEffectus, MyErrorEffectus>;
///
/// fn combine(self, _other: MyErrorEffectus) -> Self::Combined {
/// CombinedEffectus::new()
/// }
/// }
///
/// // Combine IO and Error effects
/// let combined = MyIoEffectus.combine(MyErrorEffectus);
/// let _ = combined;
/// ```
/// A combined effect type representing both effects.