Remove dependency on thiserror

This commit is contained in:
Joscha 2023-02-12 20:01:04 +01:00
parent 4a8978bbb3
commit 5c044494e7
2 changed files with 27 additions and 7 deletions

View file

@ -8,5 +8,4 @@ tokio = ["dep:tokio"]
[dependencies] [dependencies]
rusqlite = "0.28.0" rusqlite = "0.28.0"
thiserror = "1.0.37"
tokio = { version = "1.23.0", features = ["sync"], optional = true } tokio = { version = "1.23.0", features = ["sync"], optional = true }

View file

@ -1,6 +1,6 @@
//! A vault for use with [`tokio`]. //! A vault for use with [`tokio`].
use std::{any::Any, result, thread}; use std::{any::Any, error, fmt, result, thread};
use rusqlite::Connection; use rusqlite::Connection;
use tokio::sync::{mpsc, oneshot}; use tokio::sync::{mpsc, oneshot};
@ -35,15 +35,36 @@ 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)]
pub enum Error { pub enum Error {
/// The vault's thread has been stopped and its sqlite connection closed. /// The vault's thread has been stopped and its sqlite connection closed.
#[error("vault has been stopped")]
Stopped, Stopped,
/// A [`rusqlite::Error`] occurred while running the action. /// A [`rusqlite::Error`] occurred while running the action.
#[error("{0}")] Rusqlite(rusqlite::Error),
Rusqlite(#[from] rusqlite::Error), }
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Stopped => "vault has been stopped".fmt(f),
Self::Rusqlite(err) => err.fmt(f),
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::Stopped => None,
Self::Rusqlite(err) => Some(err),
}
}
}
impl From<rusqlite::Error> for Error {
fn from(value: rusqlite::Error) -> Self {
Self::Rusqlite(value)
}
} }
pub type Result<R> = result::Result<R, Error>; pub type Result<R> = result::Result<R, Error>;