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
//! Actor state access for handlers.
//!
//! [`ActorStateManager`] is the typed API handlers use through `ActorContext`.
//! It delegates to [`ActorStateClient`], which reads and writes state on the server over gRPC.
//! [`MockStateBackend`] replaces the server in tests.
//!
//! ## Layers
//!
//! ```text
//! Handler Code
//! │
//! ▼
//! ActorContext::state()
//! │
//! ▼
//! ActorStateManager (convenience API)
//! │
//! ▼
//! ActorStateClient (gRPC calls to server)
//! │
//! ▼
//! Server State Storage
//! ```
//!
//! ## Example
//!
//! ```rust
//! use orcher_sdk::prelude::*;
//!
//! #[derive(Serialize, Deserialize)]
//! pub struct Item {
//! name: String,
//! }
//!
//! # #[actor]
//! # pub struct ShoppingCart;
//! # #[operations]
//! # impl ShoppingCart {
//! #[operation(exclusive)]
//! pub async fn add_item(ctx: ActorContext, item: Item) -> Result<()> {
//! let state = ctx.state();
//! let mut cart: Vec<Item> = state
//! .get("cart")
//! .await?
//! .unwrap_or_default();
//!
//! cart.push(item);
//! state.set("cart", &cart).await?;
//!
//! Ok(())
//! }
//! # }
//! ```
pub use ;
pub use ActorStateManager;
pub use MockStateBackend;