async-sqlite 0.6.0

A library for working with sqlite asynchronously
Documentation
/// Enum of all possible errors.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
    /// Indicates that the connection to the sqlite database is closed.
    Closed,
    /// Indicates that the sqlite worker queue is full.
    QueueFull,
    /// Invalid builder configuration.
    Config { message: &'static str },
    /// Error updating PRAGMA.
    PragmaUpdate {
        name: &'static str,
        exp: &'static str,
        got: String,
    },
    /// Represents a [`rusqlite::Error`].
    Rusqlite(rusqlite::Error),
    /// A user-provided closure panicked while being executed on the worker thread.
    Panic { message: String },
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Rusqlite(err) => Some(err),
            _ => None,
        }
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::Closed => write!(f, "connection to sqlite database closed"),
            Error::QueueFull => write!(f, "sqlite worker queue is full"),
            Error::Config { message } => write!(f, "invalid configuration: {message}"),
            Error::PragmaUpdate { exp, got, name } => {
                write!(f, "updating pragma {name}: expected '{exp}', got '{got}'")
            }
            Error::Rusqlite(err) => err.fmt(f),
            Error::Panic { message } => write!(f, "user closure panicked: {message}"),
        }
    }
}

impl From<rusqlite::Error> for Error {
    fn from(value: rusqlite::Error) -> Self {
        Error::Rusqlite(value)
    }
}

impl<T> From<crossbeam_channel::SendError<T>> for Error {
    fn from(_value: crossbeam_channel::SendError<T>) -> Self {
        Error::Closed
    }
}

impl<T> From<crossbeam_channel::TrySendError<T>> for Error {
    fn from(value: crossbeam_channel::TrySendError<T>) -> Self {
        match value {
            crossbeam_channel::TrySendError::Full(_) => Error::QueueFull,
            crossbeam_channel::TrySendError::Disconnected(_) => Error::Closed,
        }
    }
}

impl From<crossbeam_channel::RecvError> for Error {
    fn from(_value: crossbeam_channel::RecvError) -> Self {
        Error::Closed
    }
}

impl From<futures_channel::oneshot::Canceled> for Error {
    fn from(_value: futures_channel::oneshot::Canceled) -> Self {
        Error::Closed
    }
}