Skip to main content

beam/adapters/
mod.rs

1//! Storage and network adapters for BEAM.
2//!
3//! This module contains all adapter implementations that connect the
4//! [`crate::Node`] graph engine to external systems:
5//!
6//! # Storage Adapters
7//!
8//! - [`MemoryStorage`] — in-memory `HashMap`-backed storage (default)
9//! - [`RedbStorage`] — persistent embedded storage via [`redb`] (native only)
10//! - [`FjallStorage`] — persistent LSM-tree storage via [`fjall`] (native only, feature-gated)
11//! - [`WasmIdbStorage`] — persistent IndexedDB storage (browser/WASM only)
12//! - [`WasmNodeFsStorage`] — persistent `node:fs/promises` storage (Node.js WASM, `node-fs` feature)
13//! - [`WasmOpfsStorage`] — persistent OPFS storage (browser/WASM only)
14//!
15//! # Storage Read/Write Split
16//!
17//! Storage adapters that implement [`Actor::try_clone_storage`] are started
18//! as two actors by the Router: a read actor (receives `Get`) and a write
19//! actor (receives `Put`, `BatchPut`, `Flush`). Both share the same
20//! underlying store via `Arc`, so reads see committed writes immediately.
21//!
22//! - [`RedbStorage`] splits — the write actor's `spawn_blocking` fsync no
23//!   longer blocks the read actor's concurrent `Get` queries.
24//! - [`FjallStorage`] splits — though less critical than redb (fjall's writes
25//!   are journal appends, not fsyncs), the split still provides backpressure
26//!   isolation.
27//! - [`MemoryStorage`] does not split — in-memory writes are synchronous
28//!   (no fsync), so splitting provides no benefit and would break
29//!   read-after-write ordering.
30//!
31//! # Network Adapters
32//!
33//! - [`OutgoingWebsocketManager`] — outgoing WebSocket client manager (native only)
34//! - [`WsServer`] — incoming WebSocket server with optional TLS (native only)
35//! - [`WsConn`] — per-connection WebSocket actor (native only)
36//! - [`Multicast`] — UDP multicast LAN discovery (native only)
37//! - [`WebRtcPeer`] — WebRTC data channel P2P connection (feature-gated)
38//!
39//! # Adapter Protocol
40//!
41//! All adapters implement the [`crate::actor::Actor`] trait and receive
42//! [`crate::message::Message`] via the actor system. Storage adapters
43//! handle `Get`, `Put`, `BatchPut`, and `Flush`. Network adapters
44//! handle `Put` and `Get` by serializing to the wire format and
45//! forwarding to remote peers.
46
47mod memory_storage;
48
49#[cfg(not(target_arch = "wasm32"))]
50mod multicast;
51
52#[cfg(feature = "persy")]
53pub mod persy_storage;
54
55#[cfg(feature = "fjall")]
56mod fjall_storage;
57
58#[cfg(not(target_arch = "wasm32"))]
59mod redb_storage;
60
61#[cfg(feature = "webrtc")]
62mod webrtc;
63
64#[cfg(not(target_arch = "wasm32"))]
65mod ws_client;
66
67#[cfg(not(target_arch = "wasm32"))]
68mod ws_conn;
69
70#[cfg(not(target_arch = "wasm32"))]
71mod ws_server;
72
73#[cfg(target_arch = "wasm32")]
74mod wasm_ws;
75
76#[cfg(target_arch = "wasm32")]
77mod wasm_idb;
78
79#[cfg(all(target_arch = "wasm32", feature = "node-fs"))]
80mod wasm_node_fs;
81
82#[cfg(target_arch = "wasm32")]
83mod wasm_opfs;
84
85pub use memory_storage::MemoryStorage;
86
87#[cfg(not(target_arch = "wasm32"))]
88pub use multicast::Multicast;
89
90#[cfg(feature = "persy")]
91pub use persy_storage::PersyStorage;
92
93#[cfg(feature = "fjall")]
94pub use fjall_storage::FjallStorage;
95
96#[cfg(not(target_arch = "wasm32"))]
97pub use redb_storage::RedbStorage;
98
99#[cfg(not(target_arch = "wasm32"))]
100pub use ws_client::OutgoingWebsocketManager;
101
102#[cfg(not(target_arch = "wasm32"))]
103pub use ws_conn::WsConn;
104
105#[cfg(not(target_arch = "wasm32"))]
106pub use ws_server::{WsServer, WsServerConfig};
107
108#[cfg(target_arch = "wasm32")]
109pub use wasm_ws::WasmWsConn;
110
111#[cfg(target_arch = "wasm32")]
112pub use wasm_idb::WasmIdbStorage;
113
114#[cfg(all(target_arch = "wasm32", feature = "node-fs"))]
115pub use wasm_node_fs::WasmNodeFsStorage;
116
117#[cfg(target_arch = "wasm32")]
118pub use wasm_opfs::WasmOpfsStorage;
119
120#[cfg(feature = "webrtc")]
121pub use webrtc::{WebRtcPeer, WebRtcRole};