Struct Mailbox

Source
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

Source

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.

Source

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.

Source

pub fn receive_pending(&self, peer_id: &str) -> Result<Vec<Message>, MailError>

Retrieve all unread messages addressed to peer_id.

The query filters on to_peer and read_at IS NULL. Returned rows are transformed back into Message structs, parsing the UUID, JSON payload, and RFC3339 timestamps.

Source

pub fn mark_read(&self, msg_id: Uuid) -> Result<(), MailError>

Mark a message as read by setting its read_at timestamp.

The current UTC time is stored in the read_at column for the row with the matching id.

Auto Trait Implementations§

§

impl !Freeze for Mailbox

§

impl !RefUnwindSafe for Mailbox

§

impl Send for Mailbox

§

impl !Sync for Mailbox

§

impl Unpin for Mailbox

§

impl !UnwindSafe for Mailbox

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.