Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Add a Sync bounds to errors #110

Merged
merged 2 commits into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
4 changes: 2 additions & 2 deletions src/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ macro_rules! error_chain_processed {
EK: Into<$error_kind_name>;
}

impl<T, E> $result_ext_name<T, E> for ::std::result::Result<T, E> where E: ::std::error::Error + Send + 'static {
impl<T, E> $result_ext_name<T, E> for ::std::result::Result<T, E> where E: ::std::error::Error + Sync + Send + 'static {
fn chain_err<F, EK>(self, callback: F) -> ::std::result::Result<T, $error_name>
where F: FnOnce() -> EK,
EK: Into<$error_kind_name> {
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -416,7 +416,7 @@ pub fn make_backtrace() -> Option<Arc<Backtrace>> {

/// 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;

Expand All @@ -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<Arc<Backtrace>>
fn extract_backtrace(e: &(error::Error + Sync + Send + 'static)) -> Option<Arc<Backtrace>>
where Self: Sized;
}

Expand All @@ -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<Box<error::Error + Send>>,
pub next_error: Option<Box<error::Error + Sync + Send>>,
/// Backtrace for the current error.
#[cfg(feature = "backtrace")]
pub backtrace: Option<Arc<Backtrace>>,
Expand All @@ -473,7 +473,7 @@ impl Default for State {
impl State {
/// Creates a new State type
#[cfg(feature = "backtrace")]
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
pub fn new<CE: ChainedError>(e: Box<error::Error + Sync + Send>) -> State {
let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace);
State {
next_error: Some(e),
Expand All @@ -483,7 +483,7 @@ impl State {

/// Creates a new State type
#[cfg(not(feature = "backtrace"))]
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
pub fn new<CE: ChainedError>(e: Box<error::Error + Sync + Send>) -> State {
State { next_error: Some(e) }
}

Expand Down