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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//! # Murmer — A distributed actor framework for Rust
//!
//! Murmer provides typed, location-transparent actors that communicate through
//! message passing. Whether an actor lives in the same process or on a remote
//! node across the network, you interact with it through the same [`Endpoint<A>`] API.
//!
//! **[Read the book →](https://paxsonsa.github.io/murmer-rs/)**
//! ·
//! **[GitHub](https://github.com/paxsonsa/murmer-rs)**
//!
//! ---
//!
//! ## Murmer in 1 minute
//!
//! ```toml
//! [dependencies]
//! murmer = "0.1"
//! serde = { version = "1", features = ["derive"] }
//! tokio = { version = "1", features = ["full"] }
//! ```
//!
//! ```rust,ignore
//! use murmer::prelude::*;
//!
//! // ① Define your actor — state lives separately
//! #[derive(Debug)]
//! struct Counter;
//! struct CounterState { count: i64 }
//!
//! impl Actor for Counter {
//! type State = CounterState;
//! }
//!
//! // ② Handlers become the actor's API
//! #[handlers]
//! impl Counter {
//! #[handler]
//! fn increment(
//! &mut self,
//! _ctx: &ActorContext<Self>,
//! state: &mut CounterState,
//! amount: i64,
//! ) -> i64 {
//! state.count += amount;
//! state.count
//! }
//!
//! #[handler]
//! fn get_count(
//! &mut self,
//! _ctx: &ActorContext<Self>,
//! state: &mut CounterState,
//! ) -> i64 {
//! state.count
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! // ③ Create a local actor system
//! let system = System::local();
//!
//! // ④ Start an actor — returns a typed Endpoint<Counter>
//! let counter = system.start("counter/main", Counter, CounterState { count: 0 });
//!
//! // ⑤ Send messages via auto-generated extension methods
//! let result = counter.increment(5).await.unwrap();
//! println!("Count: {result}"); // → Count: 5
//!
//! // ⑥ Look up actors by label — works for local and remote
//! let found = system.lookup::<Counter>("counter/main").unwrap();
//! let count = found.get_count().await.unwrap();
//! println!("Looked up: {count}"); // → Looked up: 5
//! }
//! ```
//!
//! ## What it gives you
//!
//! - **Send messages without caring where the actor lives.** `counter.increment(5)` works
//! identically whether the actor is local or on a remote node — [`Endpoint<A>`] abstracts
//! the difference away.
//! - **Test distributed systems from a single process.** [`System::local`] runs everything
//! in-memory. Swap to `System::clustered_auto` when ready for real networking — your
//! actor code stays identical.
//! - **Define actors with minimal boilerplate.** The `#[handlers]` macro auto-generates
//! message structs, dispatch tables, serialization, and ergonomic extension methods.
//! - **Get networking and encryption handled for you.** QUIC transport with automatic TLS,
//! SWIM-based cluster membership, and mDNS discovery — all configured, not hand-rolled.
//! - **Supervise actors like OTP.** Restart policies with configurable limits and
//! exponential backoff keep your system running through failures.
//!
//! ## Core concepts
//!
//! | Concept | Type | Purpose |
//! |---------|------|---------|
//! | **Actor** | [`Actor`] | Stateful message processor. State lives in an associated `State` type. |
//! | **Message** | [`Message`] | Defines a request and its response type. |
//! | **RemoteMessage** | [`RemoteMessage`] | A message that can cross the wire (serializable + `TYPE_ID`). |
//! | **Endpoint** | [`Endpoint<A>`] | Opaque send handle. Abstracts local vs remote — callers never know which. |
//! | **Receptionist** | [`Receptionist`] | Type-erased actor registry. Start, lookup, and subscribe to actors. |
//! | **Router** | [`Router<A>`] | Distributes messages across a pool of endpoints (round-robin, broadcast). |
//! | **Listing** | [`Listing<A>`] | Async stream of endpoints matching a [`ReceptionKey`]. |
//!
//! ## Location transparency
//!
//! The key design principle: [`Endpoint<A>`] hides whether the actor is local or remote.
//!
//! - **Local actors** use the [envelope pattern](wire::EnvelopeProxy) — zero serialization
//! cost, direct in-memory dispatch through a type-erased trait object.
//! - **Remote actors** serialize messages with [bincode], send them over QUIC streams,
//! and deserialize responses on return.
//!
//! The caller's code is identical in both cases:
//!
//! ```rust,ignore
//! let result = endpoint.send(Increment { amount: 5 }).await?;
//! ```
//!
//! ## Actor discovery
//!
//! The [`Receptionist`] is the central registry for actor discovery:
//!
//! - **Labels** identify actors with path-like strings (`"cache/user"`, `"worker/0"`).
//! - **Typed lookup** via `receptionist.lookup::<MyActor>("label")` returns `Option<Endpoint<A>>`.
//! - **Reception keys** group actors by type for subscription-based discovery.
//! - **Listings** provide async streams of endpoints as actors register and deregister.
//!
//! ## Supervision
//!
//! Actors are managed by supervisors that handle lifecycle and crash recovery:
//!
//! - [`RestartPolicy::Temporary`] — never restart (default)
//! - [`RestartPolicy::Transient`] — restart only on panic
//! - [`RestartPolicy::Permanent`] — always restart
//!
//! Restart limits and exponential backoff are configured via [`RestartConfig`].
//!
//! ## Clustering
//!
//! The [`cluster`] module provides multi-node actor systems over QUIC:
//!
//! - **SWIM protocol** membership via [`foca`](https://docs.rs/foca) for failure detection
//! - **mDNS discovery** for zero-configuration LAN clustering
//! - **OpLog replication** with version vectors for consistent registry views
//! - **Per-actor QUIC streams** — one multiplexed connection per node pair
//!
//! ## Going from local to clustered
//!
//! Only the system construction changes — all actor code stays identical:
//!
//! ```rust,ignore
//! // Local
//! let system = System::local();
//!
//! // Clustered
//! let config = ClusterConfig::builder()
//! .name("my-node")
//! .listen("0.0.0.0:7100".parse()?)
//! .cookie("my-cluster-secret")
//! .build()?;
//!
//! let system = System::clustered_auto(config).await?;
//! ```
//!
//! ## Learn more
//!
//! - **[The Murmer Book](https://paxsonsa.github.io/murmer-rs/)** — full guide with
//! examples, diagrams, and deep-dives into every component
//! - [`cluster`] — multi-node clustering and networking
//! - [`receptionist`] — actor discovery and subscriptions
//! - [`lifecycle`] — supervision, restart policies, and actor factories
//! - [`router`] — round-robin and broadcast routing across actor pools
// Allow proc-macro-generated code (e.g. `#[handlers]`) to reference `murmer::`
// and `::murmer::` when used inside this crate — same pattern as serde.
extern crate self as murmer;
pub
/// Re-export dependencies so generated code can reference them without the user
/// needing them in their Cargo.toml.
// =============================================================================
// AUTO-REGISTRATION — linkme distributed slice for TypeRegistry entries
// =============================================================================
/// An entry for auto-registration of an actor type in the cluster's [`cluster::sync::TypeRegistry`].
///
/// The `#[handlers]` macro emits one of these per actor type into the
/// [`ACTOR_TYPE_ENTRIES`] distributed slice. At startup, [`cluster::sync::TypeRegistry::from_auto()`]
/// iterates the slice to build the registry automatically.
// TypeRegistryEntry contains only function pointers — inherently Send + Sync.
unsafe
/// Distributed slice populated by `#[handlers]` macro expansions across all crates.
///
/// Each actor type annotated with `#[handlers]` contributes one [`TypeRegistryEntry`]
/// to this slice at link time. Use [`cluster::sync::TypeRegistry::from_auto()`] to
/// collect them into a ready-to-use registry.
pub static ACTOR_TYPE_ENTRIES: ;
// =============================================================================
// FEATURE RE-EXPORTS
// =============================================================================
/// Re-export proc macros from `murmer-macros` (enabled by the `macros` feature, on by default).
///
/// This lets users write `use murmer::handlers;` instead of depending on `murmer-macros` directly.
pub use ;
/// Convenience prelude — import everything you need for typical actor definitions.
///
/// ```rust,ignore
/// use murmer::prelude::*;
/// ```
// Re-export core types for convenience
pub use ;
pub use ;
pub use ;
pub use Endpoint;
pub use ;
pub use ;
pub use run_node_receiver;
pub use ;
pub use ReadyHandle;
pub use ;
pub use ;
pub use ;
pub use ;
pub use System;
pub use ;