Document more things

This commit is contained in:
Joscha 2022-12-15 11:17:09 +01:00
parent 5142b6604e
commit f37b4aa81c
2 changed files with 14 additions and 4 deletions

View file

@ -14,6 +14,13 @@ pub mod tokio;
use rusqlite::Connection; use rusqlite::Connection;
/// An action that can be performed on a [`Connection`].
///
/// Both commands and queries are considered actions. Commands usually have a
/// return type of `()`, while queries return the result of the query.
///
/// Actions are usually passed to a vault which will then execute them and
/// return the result. The way in which this occurs depends on the vault.
pub trait Action { pub trait Action {
type Result; type Result;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result>; fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result>;

View file

@ -1,3 +1,5 @@
//! A vault for use with `tokio`.
use std::{any::Any, result, thread}; use std::{any::Any, result, thread};
use rusqlite::{Connection, Transaction}; use rusqlite::{Connection, Transaction};
@ -35,8 +37,8 @@ enum Command {
/// Error that can occur during execution of an [`Action`]. /// Error that can occur during execution of an [`Action`].
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
/// The vault thread has stopped. /// The vault's thread has been stopped and its sqlite connection closed.
#[error("vault thread has stopped")] #[error("vault has been stopped")]
Stopped, Stopped,
/// A [`rusqlite::Error`] occurred while running the action. /// A [`rusqlite::Error`] occurred while running the action.
@ -92,6 +94,7 @@ fn run(mut conn: Connection, mut rx: mpsc::UnboundedReceiver<Command>) {
} }
} }
/// A vault for use with `tokio`.
#[derive(Clone)] #[derive(Clone)]
pub struct TokioVault { pub struct TokioVault {
tx: mpsc::UnboundedSender<Command>, tx: mpsc::UnboundedSender<Command>,
@ -158,9 +161,9 @@ impl TokioVault {
Ok(*result) Ok(*result)
} }
/// Stop the vault thread. /// Stop the vault's thread and close its sqlite connection.
/// ///
/// Returns when the vault has been stopped successfully. /// Returns once the vault has been stopped.
pub async fn stop(&self) { pub async fn stop(&self) {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let _ = self.tx.send(Command::Stop(tx)); let _ = self.tx.send(Command::Stop(tx));