Bring back Fail

This commit is contained in:
asonix 2019-09-17 17:49:45 -05:00
parent b017803b74
commit 0522c83c33
3 changed files with 12 additions and 19 deletions

View file

@ -2,7 +2,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration};
use actix::{Actor, Addr, Arbiter, SyncArbiter}; use actix::{Actor, Addr, Arbiter, SyncArbiter};
use background_jobs_core::{Job, Processor, ProcessorMap, Stats, Storage}; use background_jobs_core::{Job, Processor, ProcessorMap, Stats, Storage};
use failure::Error; use failure::{Error, Fail};
use futures::Future; use futures::Future;
mod every; mod every;
@ -28,7 +28,7 @@ pub struct ServerConfig<S> {
impl<S> ServerConfig<S> impl<S> ServerConfig<S>
where where
S: Storage + Sync + 'static, S: Storage + Sync + 'static,
S::Error: Send + Sync, S::Error: Fail,
{ {
/// Create a new ServerConfig /// Create a new ServerConfig
pub fn new(storage: S) -> Self { pub fn new(storage: S) -> Self {

View file

@ -1,5 +1,5 @@
use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Stats, Storage}; use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Stats, Storage};
use failure::Error; use failure::{Error, Fail};
pub(crate) trait ActixStorage { pub(crate) trait ActixStorage {
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error>; fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error>;
@ -11,17 +11,15 @@ pub(crate) trait ActixStorage {
fn get_stats(&self) -> Result<Stats, Error>; fn get_stats(&self) -> Result<Stats, Error>;
} }
pub(crate) struct StorageWrapper<S, E>(pub(crate) S) pub(crate) struct StorageWrapper<S>(pub(crate) S)
where where
S: Storage<Error = E>, S: Storage,
S::Error: Send, S::Error: Fail;
E: std::error::Error + Send;
impl<S, E> ActixStorage for StorageWrapper<S, E> impl<S> ActixStorage for StorageWrapper<S>
where where
S: Storage<Error = E>, S: Storage,
S::Error: Send, S::Error: Fail,
E: std::error::Error + Send + Sync + 'static,
{ {
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error> { fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error> {
self.0.new_job(job).map_err(Error::from) self.0.new_job(job).map_err(Error::from)

View file

@ -18,6 +18,7 @@
*/ */
use chrono::offset::Utc; use chrono::offset::Utc;
use failure::Fail;
use log::error; use log::error;
use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats}; use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats};
@ -30,7 +31,7 @@ use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats};
/// the `background-jobs-sled-storage` crate. /// the `background-jobs-sled-storage` crate.
pub trait Storage: Clone + Send { pub trait Storage: Clone + Send {
/// The error type used by the storage mechansim. /// The error type used by the storage mechansim.
type Error: std::error::Error; type Error: Fail;
/// This method generates unique IDs for jobs /// This method generates unique IDs for jobs
fn generate_id(&mut self) -> Result<u64, Self::Error>; fn generate_id(&mut self) -> Result<u64, Self::Error>;
@ -264,7 +265,7 @@ pub mod memory_storage {
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, Fail)]
pub enum Never {} pub enum Never {}
impl fmt::Display for 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)] #[derive(Clone, Debug, Fail)]
#[fail(display = "Created too many storages, can't generate any more IDs")] #[fail(display = "Created too many storages, can't generate any more IDs")]
pub struct TooManyStoragesError; pub struct TooManyStoragesError;