From 0522c83c3389e66ee1c6568ae1cceaef5a7f1b5c Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 17 Sep 2019 17:49:45 -0500 Subject: [PATCH] Bring back Fail --- jobs-actix/src/lib.rs | 4 ++-- jobs-actix/src/storage.rs | 16 +++++++--------- jobs-core/src/storage.rs | 11 +++-------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/jobs-actix/src/lib.rs b/jobs-actix/src/lib.rs index 78a62d5..df5982c 100644 --- a/jobs-actix/src/lib.rs +++ b/jobs-actix/src/lib.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration}; use actix::{Actor, Addr, Arbiter, SyncArbiter}; use background_jobs_core::{Job, Processor, ProcessorMap, Stats, Storage}; -use failure::Error; +use failure::{Error, Fail}; use futures::Future; mod every; @@ -28,7 +28,7 @@ pub struct ServerConfig { impl ServerConfig where S: Storage + Sync + 'static, - S::Error: Send + Sync, + S::Error: Fail, { /// 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 e8ae406..28cbcb3 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; +use failure::{Error, Fail}; pub(crate) trait ActixStorage { fn new_job(&mut self, job: NewJobInfo) -> Result; @@ -11,17 +11,15 @@ pub(crate) trait ActixStorage { fn get_stats(&self) -> Result; } -pub(crate) struct StorageWrapper(pub(crate) S) +pub(crate) struct StorageWrapper(pub(crate) S) where - S: Storage, - S::Error: Send, - E: std::error::Error + Send; + S: Storage, + S::Error: Fail; -impl ActixStorage for StorageWrapper +impl ActixStorage for StorageWrapper where - S: Storage, - S::Error: Send, - E: std::error::Error + Send + Sync + 'static, + S: Storage, + S::Error: Fail, { 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 689c22c..48e4e32 100644 --- a/jobs-core/src/storage.rs +++ b/jobs-core/src/storage.rs @@ -18,6 +18,7 @@ */ use chrono::offset::Utc; +use failure::Fail; use log::error; use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats}; @@ -30,7 +31,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: std::error::Error; + type Error: Fail; /// This method generates unique IDs for jobs fn generate_id(&mut self) -> Result; @@ -264,7 +265,7 @@ pub mod memory_storage { } } - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Fail)] pub enum Never {} impl fmt::Display for Never { @@ -273,12 +274,6 @@ 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;