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
//! # actr-framework
//!
//! Actor-RTC core programming interface layer - defines the contract for user-framework interaction.
//!
//! ## Architectural Positioning
//!
//! `actr-framework` is the **SDK interface layer** of the actr system, positioned in the middle tier:
//!
//! ```text
//! User Application (Workload implementation)
//! ↓ depends on
//! actr-framework (this crate) ← Stable API contract (trait definitions only)
//! ↓ depends on
//! actr-protocol ← Data type definitions
//! ↑ implements
//! actr-runtime ← Runtime implementation (implements Context trait)
//! ```
//!
//! ## Core Responsibilities
//!
//! 1. **Define user programming interface**: `Workload`, `MessageDispatcher` traits
//! 2. **Define execution context interface**: `Context` trait (implemented by runtime)
//! 3. **Type-safe RPC**: `Context::call()` and `Context::tell()` methods
//! 4. **Lifecycle management**: `on_start`, `on_stop` hooks
//!
//! ## Design Principles
//!
//! ### 1. Interface-only, Zero Implementation
//!
//! ```rust,ignore
//! // ✅ Framework defines
//! pub trait Context {
//! async fn call<R: RpcRequest>(...) -> ActorResult<R::Response>;
//! }
//!
//! // ✅ Runtime implements
//! impl Context for RuntimeContext { ... }
//! ```
//!
//! Framework **contains no implementation code**, all logic is in runtime.
//!
//! ### 2. Dependency Inversion Principle
//!
//! - Framework defines traits, Runtime implements traits
//! - User code only depends on framework, not runtime
//! - Context trait can be mocked for unit testing
//!
//! ### 3. Zero-Cost Abstraction
//!
//! - Use generics instead of trait objects (`<C: Context>` not `&dyn Context`)
//! - Compile-time monomorphization, static dispatch
//! - Compiler can fully inline the entire call chain
//! - Zero virtual function call overhead
//!
//! ## Core Type System
//!
//! ### 4-Trait Architecture
//!
//! actr builds a type-safe message handling system with 4 traits:
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────┐
//! │ 1. RpcRequest trait (actr-protocol) │
//! │ - Associates Request and Response types │
//! │ - Provides route_key() static method │
//! └─────────────────────────────────────────────────────────┘
//! ↓ used by
//! ┌─────────────────────────────────────────────────────────┐
//! │ 2. Concrete Handler trait (code generated) │
//! │ - e.g., EchoServiceHandler<C: Context> │
//! │ - async fn echo<C: Context>(&self, req, ctx: &C) │
//! └─────────────────────────────────────────────────────────┘
//! ↓ wrapped by
//! ┌─────────────────────────────────────────────────────────┐
//! │ 3. MessageDispatcher trait (this crate) │
//! │ - Static routing: route_key → handler method │
//! │ - Zero-sized type (ZST), zero runtime overhead │
//! └─────────────────────────────────────────────────────────┘
//! ↓ associated with
//! ┌─────────────────────────────────────────────────────────┐
//! │ 4. Workload trait (this crate) │
//! │ - Associates Dispatcher type │
//! │ - Provides on_start(), on_stop() hooks │
//! └─────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Usage Example
//!
//! ```rust,ignore
//! use actr_framework::{Context, Workload};
//!
//! // Code-generated Handler trait
//! #[async_trait]
//! pub trait EchoServiceHandler: Send + Sync + 'static {
//! async fn echo<C: Context>(
//! &self,
//! req: EchoRequest,
//! ctx: &C,
//! ) -> ActorResult<EchoResponse>;
//! }
//!
//! // User implements business logic
//! impl EchoServiceHandler for MyService {
//! async fn echo<C: Context>(
//! &self,
//! req: EchoRequest,
//! ctx: &C,
//! ) -> ActorResult<EchoResponse> {
//! // Access context data
//! tracing::info!("trace_id: {}", ctx.trace_id());
//!
//! // Type-safe RPC call
//! let response = ctx.call(&target, another_request).await?;
//!
//! Ok(EchoResponse {
//! reply: format!("Echo: {}", req.message),
//! })
//! }
//! }
//! ```
// Module declarations
// Optional utilities module
// Guest-side runtime module (WASM and dynclib ABI)
// Web-target (`wasm32-unknown-unknown`) runtime glue. Compiled only when
// the `web` feature is enabled on a wasm32 build — see `src/web/mod.rs`
// for the target / feature gating rationale.
// Test helpers (lightweight Context implementation)
// Only compiled under the test-utils feature (includes uuid v4, incompatible with wasm32 target)
// Public re-exports
pub use ;
pub use Dest;
pub use MessageDispatcher;
pub use ServiceHandler;
pub use ;
// Re-export commonly used types for user convenience
pub use Bytes;
// Re-export async_trait to avoid users having to add it as a dependency
pub use async_trait;
// Re-export DataStream from protocol
pub use DataStream;
// Re-export backoff utilities
pub use ;