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
208
209
210
211
212
213
214
215
216
217
//! Procedural macros for the workspace `effect` crate.
//!
//! Doc links cannot use the `id_effect::…` prefix here: this crate defines an `effect` function, which
//! shadows the `effect` crate name in rustdoc link resolution.
use TokenStream;
/// Compiles and runs the README examples as doctests.
;
/// Derive macro: structural [`PartialEq`], [`Eq`], and [`Hash`] for Effect.ts-style data types.
///
/// Types implementing these impls automatically satisfy [`id_effect::schema::data::EffectData`] via the
/// blanket implementation in the `effect` crate.
/// Injects `pub _tag: &'static str`, an [`id_effect::match_::HasTag`] impl, and
/// `EFFECT_TAGGED_TAG` on the struct (see generated inherent associated const).
///
/// Only supports structs with **named fields**. Place **above** `#[derive(EffectData, …)]`.
/// Derive an inherent `layer()` (an `id_effect::Layer` providing the service) from
/// `#[provides(Service)]`. Re-exported by `id_effect` as `ProviderSpecDerive`.
///
/// `Struct::layer::<E>()` is a `Layer<HCons<Service, HNil>, E>` that needs nothing and never
/// fails. The service value comes from, in order of precedence:
///
/// - `#[provides(Service, with = <constructor>)]` — `|| expr`, or a path such as `Self::build`
/// called with no arguments. This is the recommended form: no `fn new() -> Service` (which
/// trips `clippy::new_ret_no_self`) is needed.
/// - `Self::default()` when the struct derives `Default` (the provider is its own service).
/// - `Self::new()` otherwise.
///
/// `#[provides(Service, release = <finalizer>)]` makes it an `acquire_release` layer whose
/// finalizer `release(Arc<Service>)` (an `Effect<(), Never, HNil>`) runs when the layer's scope
/// closes. The 0.6 forms `|deps: &Env| ..` and `#[named("..")]` are compile errors.
///
/// ```ignore
/// #[derive(Clone)]
/// struct Counter(u32);
///
/// #[derive(ProviderSpecDerive)]
/// #[provides(Counter, with = || Counter(42))]
/// struct CounterLive;
///
/// let program = app().provide_layer(CounterLive::layer());
/// ```
/// Enum match helper — prefix variant patterns with `EnumPath` for exhaustiveness checking.
///
/// ```ignore
/// match_effect!(Color, value, {
/// Red(n) => n,
/// Green => 0,
/// Blue => 1,
/// })
/// ```
/// Do-notation over an async body, building an `id_effect::Effect`.
///
/// `effect!({ body })` takes `R` from the expected type; `effect!(|r: &Caps| { body })` fixes
/// `R = Caps` and binds `r: &Caps`. In the body, `~Cap` reads a capability (`&Arc<Cap>`),
/// `~expr` runs a sub-effect over a part of `R` on the same fiber, widening its error (`Never`
/// to anything, else `E: From<E2>`), and `~(a, b, ..)` joins up to 8 effects in parallel on
/// child fibers. `?` on a `Result` fails the effect with its error. The body must be `Send`.
///
/// ```
/// use id_effect::{Effect, Exit, Never, caps, effect, succeed};
///
/// struct Greeting(&'static str);
///
/// fn answer() -> Effect<u32> {
/// succeed(42)
/// }
///
/// fn hello() -> Effect<String, Never, caps!(Greeting)> {
/// effect!({ format!("{}:{}", ~Greeting.0, ~answer()) })
/// }
///
/// let out = hello().provide(Greeting("hi")).block_on();
/// assert!(matches!(out, Exit::Success(ref s) if s == "hi:42"));
/// ```
/// Like `effect!`, but builds an `id_effect::LocalEffect`, whose body may hold `!Send` values.
/// `~expr` binds a `LocalEffect` or a `Send` `Effect` over a part of `R`.
/// `caps!(A, B, C)` is the environment type `HCons<A, HCons<B, HCons<C, HNil>>>`. A capability
/// listed twice (compared by token) is one compile error at the repeat; the de-duplicated list
/// is still emitted so no further errors cascade.
/// Derive field lenses and enum prisms for [`id_effect_optics`].
/// Derive `id_effect_fsm::Fsm` (initial state + transition table) for a fieldless state enum.
///
/// Use it through the re-export `id_effect_fsm::Fsm`; the generated impl names
/// `::id_effect_fsm` unless overridden with `crate = path`.
///
/// - Container: `#[fsm(event = EventType, initial = Variant, crate = path)]` — `event` is
/// required; `initial` defaults to the first variant.
/// - Variant: `#[fsm(on(Event => Target, ..))]`, repeatable. A bare `Event` resolves to
/// `EventType::Event`; a multi-segment path is used as written.
///
/// Unknown targets, unknown `initial`, data-carrying variants, generic enums, and duplicate
/// `(state, event)` edges are compile errors.
///
/// ```ignore
/// use id_effect_fsm::Fsm;
///
/// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// enum DoorEvent { Open, Close }
///
/// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Fsm)]
/// #[fsm(event = DoorEvent, initial = Closed)]
/// enum Door {
/// #[fsm(on(Open => Opened))]
/// Closed,
/// #[fsm(on(Close => Closed))]
/// Opened,
/// }
///
/// let mut door = Door::state_machine();
/// door.step(DoorEvent::Open).unwrap();
/// assert_eq!(door.state(), Door::Opened);
/// ```
/// Derive an inherent `schema()` constructor and an [`id_effect::schema::HasSchema`] impl for a
/// struct with named fields (JSON-shaped [`id_effect::schema::Unknown`] wire).
///
/// Rename a field on the wire with `#[schema("wire_name")]`.
///
/// The schema carries a `SchemaAst` (`schema().ast()`), so JSON Schema export (`schema-serde`)
/// describes the struct: every field is `required` except `Option<_>` fields (missing or `null`),
/// `i32` fields carry their range, and nested `HasSchema` fields are `$ref`s into `$defs` keyed by
/// type path (recursive types terminate). Enums are not supported.
///
/// ```
/// use id_effect::Schema;
/// use id_effect::schema::{HasSchema, Unknown};
///
/// #[derive(Clone, Debug, PartialEq, Schema)]
/// struct User {
/// #[schema("user_name")]
/// name: String,
/// age: i64,
/// }
///
/// let wire = User::schema().encode(User { name: "Ada".into(), age: 36 });
/// let back = <User as HasSchema>::schema().decode_unknown(&wire).unwrap();
/// assert_eq!(back.name, "Ada");
/// assert!(matches!(wire, Unknown::Object(_)));
/// ```
/// Mark a process struct as a remotely spawnable behavior.
///
/// ```ignore
/// #[distributed_behavior("counter")]
/// struct Counter { ... }
/// // Counter::BEHAVIOR_NAME == "counter"
/// // Counter::register_behavior(&mut registry);
/// ```