From b017803b74e286a2525ced1fafa839a56d6e052e Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 16 Sep 2019 20:31:11 -0500 Subject: [PATCH] Use stable sled-extensions --- examples/actix-example/Cargo.toml | 2 +- jobs-actix/src/lib.rs | 1 + jobs-actix/src/storage.rs | 8 +++++--- jobs-core/src/storage.rs | 11 ++++++++--- jobs-sled/Cargo.toml | 2 +- jobs-sled/src/lib.rs | 4 ++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/actix-example/Cargo.toml b/examples/actix-example/Cargo.toml index fa88cae..fd289ab 100644 --- a/examples/actix-example/Cargo.toml +++ b/examples/actix-example/Cargo.toml @@ -11,6 +11,6 @@ actix = "0.8" background-jobs = { version = "0.6.0", path = "../.." } failure = "0.1" futures = "0.1" -sled-extensions = { version = "0.1.0", git = "https://git.asonix.dog/asonix/sled-extensions" } +sled-extensions = "0.1.0" serde = "1.0" serde_derive = "1.0" diff --git a/jobs-actix/src/lib.rs b/jobs-actix/src/lib.rs index fcc9835..78a62d5 100644 --- a/jobs-actix/src/lib.rs +++ b/jobs-actix/src/lib.rs @@ -28,6 +28,7 @@ pub struct ServerConfig { impl ServerConfig where S: Storage + Sync + 'static, + S::Error: Send + Sync, { /// Create a new ServerConfig pub fn new(storage: S) -> Self { diff --git a/jobs-actix/src/storage.rs b/jobs-actix/src/storage.rs index 76b39f2..e8ae406 100644 --- a/jobs-actix/src/storage.rs +++ b/jobs-actix/src/storage.rs @@ -1,5 +1,5 @@ use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Stats, Storage}; -use failure::{Error, Fail}; +use failure::Error; pub(crate) trait ActixStorage { fn new_job(&mut self, job: NewJobInfo) -> Result; @@ -14,12 +14,14 @@ pub(crate) trait ActixStorage { pub(crate) struct StorageWrapper(pub(crate) S) where S: Storage, - E: Fail; + S::Error: Send, + E: std::error::Error + Send; impl ActixStorage for StorageWrapper where S: Storage, - E: Fail, + S::Error: Send, + E: std::error::Error + Send + Sync + 'static, { fn new_job(&mut self, job: NewJobInfo) -> Result { self.0.new_job(job).map_err(Error::from) diff --git a/jobs-core/src/storage.rs b/jobs-core/src/storage.rs index 48e4e32..689c22c 100644 --- a/jobs-core/src/storage.rs +++ b/jobs-core/src/storage.rs @@ -18,7 +18,6 @@ */ use chrono::offset::Utc; -use failure::Fail; use log::error; use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats}; @@ -31,7 +30,7 @@ use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats}; /// the `background-jobs-sled-storage` crate. pub trait Storage: Clone + Send { /// The error type used by the storage mechansim. - type Error: Fail; + type Error: std::error::Error; /// This method generates unique IDs for jobs fn generate_id(&mut self) -> Result; @@ -265,7 +264,7 @@ pub mod memory_storage { } } - #[derive(Clone, Debug, Fail)] + #[derive(Clone, Debug)] pub enum Never {} impl fmt::Display for Never { @@ -274,6 +273,12 @@ pub mod memory_storage { } } + impl std::error::Error for Never { + fn description(&self) -> &str { + match *self {} + } + } + #[derive(Clone, Debug, Fail)] #[fail(display = "Created too many storages, can't generate any more IDs")] pub struct TooManyStoragesError; diff --git a/jobs-sled/Cargo.toml b/jobs-sled/Cargo.toml index f87fcde..20d7c1f 100644 --- a/jobs-sled/Cargo.toml +++ b/jobs-sled/Cargo.toml @@ -13,4 +13,4 @@ edition = "2018" [dependencies] background-jobs-core = { version = "0.6", path = "../jobs-core" } chrono = "0.4" -sled-extensions = { version = "0.1", git = "https://git.asonix.dog/asonix/sled-extensions", features = ["bincode", "cbor"] } +sled-extensions = { version = "0.1", features = ["bincode", "cbor"] } diff --git a/jobs-sled/src/lib.rs b/jobs-sled/src/lib.rs index d29de0f..d2c84ce 100644 --- a/jobs-sled/src/lib.rs +++ b/jobs-sled/src/lib.rs @@ -1,8 +1,8 @@ use background_jobs_core::{JobInfo, Stats, Storage}; use chrono::offset::Utc; -use sled_extensions::{structured::{cbor, bincode::Tree}, Db, DbExt}; +use sled_extensions::{bincode::Tree, cbor, Db, DbExt}; -pub use sled_extensions::error::{Result, Error}; +pub use sled_extensions::{Error, Result}; #[derive(Clone)] pub struct SledStorage {