memory only.Expand description
In-memory reference implementation of ChatBackend.
Gated behind feature = "memory". Not production. See memory for
the full module documentation.
In-memory reference implementation of ChatBackend.
§This is a reference implementation, not production
MemoryBackend is intended for three audiences:
- Workspace integration tests — every
tests/*.rsintegration test in this crate exercises method handlers against this backend. - Downstream contributors — a documented, complete, source-readable
implementation of the
ChatBackendtrait to study when writing a real (database-backed) backend. - Examples and smoke tests — boot a real JMAP-for-Chat dispatcher with one line of code, without standing up a database.
It is not suitable for production: all state is held in HashMaps
behind a std::sync::Mutex, persistence is not implemented, and a number
of JMAP Chat draft edge cases are simplified (see source comments).
§Feature flag and API stability
This module is gated behind feature = "memory" and is not enabled
by default. Its public API stability is opt-in: it may break across
minor versions while the crate is pre-1.0.
§Example
use std::sync::Arc;
use jmap_chat_server::{memory::MemoryBackend, register_chat_handlers};
use jmap_server::Dispatcher;
let mut dispatcher: Dispatcher<()> = Dispatcher::new();
register_chat_handlers(&mut dispatcher, Arc::new(MemoryBackend::new()));§Concurrency
std::sync::Mutex is used for simplicity. The await_holding_lock
clippy lint is enabled module-wide and enforces that no lock guard
is held across an .await. If a future change requires holding a
guard across .await, switch to tokio::sync::Mutex rather than
disabling the lint.
Every lock() in this module ends in a bare .unwrap() on purpose.
Mutex::lock fails only when another thread panicked while holding the
guard, so the state behind it may be half-updated; that panic is
already a bug in this module, and there is no consistent state to
recover. Panicking again surfaces it instead of serving corrupt data.
The crate’s tests never poison the lock. A production backend that must
survive a poisoned lock should implement the trait with its own locking
rather than copy this pattern.
§Tracking
Promoted from tests/common/mod.rs per Beads issue JMAP-hwdv (epic)
and JMAP-hwdv.3 (this crate, mirror of canonical JMAP-hwdv.1 in
jmap-mail-server).
Structs§
- Memory
Backend - A fully in-memory implementation of
ChatBackend. - Memory
Error - Opaque storage-layer error returned by
MemoryBackendoperations.
Enums§
- Lifecycle
Event - One lifecycle callback received by the
MemoryBackend, as returned byMemoryBackend::drain_lifecycle_events.
Constants§
- MAX_
PUSH_ SUBSCRIPTIONS - The most push subscriptions the single owner may hold at once.