matter_controller/store/mod.rs
1//! Persistence abstraction. The controller writes an opaque, versioned
2//! snapshot blob through this trait; it never assumes a filesystem.
3
4mod file;
5pub use file::FileStore;
6
7/// Errors a [`ControllerStore`] may return.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum StoreError {
11 /// An underlying I/O operation failed.
12 #[error("I/O error: {0}")]
13 Io(#[from] std::io::Error),
14}
15
16/// A durable home for the controller's snapshot blob.
17///
18/// The controller owns the blob *format* (a versioned TLV encoding); the
19/// store only moves opaque bytes. Implementors are responsible for
20/// at-rest protection — the snapshot contains private keys in the clear.
21pub trait ControllerStore: Send + Sync {
22 /// Load the persisted snapshot, or `None` if nothing has been stored yet.
23 ///
24 /// # Errors
25 ///
26 /// Returns [`StoreError`] if the backing store cannot be read.
27 fn load(&self) -> Result<Option<Vec<u8>>, StoreError>;
28
29 /// Atomically replace the persisted snapshot.
30 ///
31 /// # Errors
32 ///
33 /// Returns [`StoreError`] if the backing store cannot be written.
34 fn save(&self, snapshot: &[u8]) -> Result<(), StoreError>;
35}