pub struct Mailbox { /* private fields */ }Expand description
Wrapper around a SQLite connection providing mailbox‑style functionalities.
The Mailbox abstracts a SQLite database that stores Message records. It offers a minimal
API for opening/creating the DB, sending messages, receiving pending messages for a peer, and
marking messages as read.
§Architectural Rationale
Using SQLite (via rusqlite) provides a zero‑configuration, file‑based persistence layer that is
portable across the various environments where CHORUS components may run. The wrapper isolates the
rest of the codebase from raw SQL handling, ensuring a single place for schema evolution and error
mapping.
Implementations§
Source§impl Mailbox
impl Mailbox
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self, MailError>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, MailError>
Open (or create) a mailbox database at path.
The function creates the SQLite file if it does not exist, enables WAL mode for better
concurrency, and ensures the messages table is present.
Sourcepub fn send(&self, msg: &Message) -> Result<(), MailError>
pub fn send(&self, msg: &Message) -> Result<(), MailError>
Store a new message in the mailbox.
The payload field is serialised to a JSON string before insertion. The read_at column is
initialised to NULL because the message has not yet been consumed.