diff --git a/CHANGELOG.md b/CHANGELOG.md index 896d8f329..7e82ca861 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- [Add a `Sync` bound to errors](https://github.com/brson/error-chain/pul/110) + # 0.7.2 - Add `quick_main!` (#88). diff --git a/src/error_chain.rs b/src/error_chain.rs index 7b1050fd8..c90e27f03 100644 --- a/src/error_chain.rs +++ b/src/error_chain.rs @@ -280,7 +280,7 @@ macro_rules! error_chain_processed { EK: Into<$error_kind_name>; } - impl $result_ext_name for ::std::result::Result where E: ::std::error::Error + Send + 'static { + impl $result_ext_name for ::std::result::Result where E: ::std::error::Error + Sync + Send + 'static { fn chain_err(self, callback: F) -> ::std::result::Result where F: FnOnce() -> EK, EK: Into<$error_kind_name> { @@ -373,7 +373,7 @@ macro_rules! impl_extract_backtrace { ($error_name: ident $error_kind_name: ident $([$link_error_path: path, $(#[$meta_links: meta])*])*) => { - fn extract_backtrace(e: &(::std::error::Error + Send + 'static)) + fn extract_backtrace(e: &(::std::error::Error + Sync + Send + 'static)) -> Option<::std::sync::Arc<$crate::Backtrace>> { if let Some(e) = e.downcast_ref::<$error_name>() { return e.1.backtrace.clone(); diff --git a/src/lib.rs b/src/lib.rs index a4bf9a6d2..e6a56df34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ //! * Conversions between error types are done in an automatic and //! consistent way - `From` conversion behavior is never specified //! explicitly. -//! * Errors implement Send. +//! * Errors implement `Sync` and `Send`. //! * Errors can carry backtraces. //! //! Similar to other libraries like [error-type] and [quick-error], @@ -61,11 +61,11 @@ //! * Instead of defining the custom `Error` type as an enum, it is a //! struct containing an `ErrorKind` (which defines the //! `description` and `display` methods for the error), an opaque, -//! optional, boxed `std::error::Error + Send + 'static` object +//! optional, boxed `std::error::Error + Sync + Send + 'static` object //! (which defines the `cause`, and establishes the links in the //! error chain), and a `Backtrace`. //! * The macro also defines a `ResultExt` trait that defines a -//! `chain_err` method. This method on all `std::error::Error + Send + 'static` +//! `chain_err` method. This method on all `std::error::Error + Sync + Send + 'static` //! types extends the error chain by boxing the current //! error into an opaque object and putting it inside a new concrete //! error. @@ -86,7 +86,7 @@ //! requiring an `Into` or `From` conversion; as well as slightly //! more cumbersome to match on errors with another layer of types //! to match. -//! * Because the error type contains `std::error::Error + Send + 'static` objects, +//! * Because the error type contains `std::error::Error + Sync + Send + 'static` objects, //! it can't implement `PartialEq` for easy comparisons. //! //! ## Declaring error types @@ -261,7 +261,7 @@ //! ``` //! //! `chain_err` can be called on any `Result` type where the contained -//! error type implements `std::error::Error + Send + 'static`. If +//! error type implements `std::error::Error + Sync + Send + 'static`. If //! the `Result` is an `Err` then `chain_err` evaluates the closure, //! which returns *some type that can be converted to `ErrorKind`*, //! boxes the original error to store as the cause, then returns a new @@ -416,7 +416,7 @@ pub fn make_backtrace() -> Option> { /// This trait is implemented on all the errors generated by the `error_chain` /// macro. -pub trait ChainedError: error::Error + Send + 'static { +pub trait ChainedError: error::Error + Sync + Send + 'static { /// Associated kind type. type ErrorKind; @@ -440,7 +440,7 @@ pub trait ChainedError: error::Error + Send + 'static { /// of the errors from `foreign_links`. #[cfg(feature = "backtrace")] #[doc(hidden)] - fn extract_backtrace(e: &(error::Error + Send + 'static)) -> Option> + fn extract_backtrace(e: &(error::Error + Sync + Send + 'static)) -> Option> where Self: Sized; } @@ -449,7 +449,7 @@ pub trait ChainedError: error::Error + Send + 'static { #[doc(hidden)] pub struct State { /// Next error in the error chain. - pub next_error: Option>, + pub next_error: Option>, /// Backtrace for the current error. #[cfg(feature = "backtrace")] pub backtrace: Option>, @@ -473,7 +473,7 @@ impl Default for State { impl State { /// Creates a new State type #[cfg(feature = "backtrace")] - pub fn new(e: Box) -> State { + pub fn new(e: Box) -> State { let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace); State { next_error: Some(e), @@ -483,7 +483,7 @@ impl State { /// Creates a new State type #[cfg(not(feature = "backtrace"))] - pub fn new(e: Box) -> State { + pub fn new(e: Box) -> State { State { next_error: Some(e) } }