Encapsulate error_chain Error inside io::Error


#1

Hello people :wave:

How can I convert my error_chain Error into an io::Error? I tried my_error_chain_result.map_err(|e| io::Error::new(io::ErrorKind::Other, e)) but it complained because the error_chain Error does not implement Send.

error[E0277]: the trait bound `std::error::Error + std::marker::Send + 'static: std::marker::Sync` is not satisfied
  --> src\main.rs:90:31
   |
90 |             .map_err(move |e| io::Error::new(io::ErrorKind::Other, e));
   |                               ^^^^^^^^^^^^^^ the trait `std::marker::Sync` is not implemented for `std::error::Error + std::marker::Send + 'static`
   |
   = note: `std::error::Error + std::marker::Send + 'static` cannot be shared between threads safely
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<std::error::Error + std::marker::Send + 'static>`
   = note: required because it appears within the type `std::boxed::Box<std::error::Error + std::marker::Send + 'static>`
   = note: required because it appears within the type `std::option::Option<std::boxed::Box<std::error::Error + std::marker::Send + 'static>>`
   = note: required because it appears within the type `error_chain::State`
   = note: required because it appears within the type `errors::Error`
   = note: required because of the requirements on the impl of `std::convert::From<errors::Error>` for `std::boxed::Box<std::error::Error + std::marker::Send + std::marker::Sync + 'static>`
   = note: required because of the requirements on the impl of `std::convert::Into<std::boxed::Box<std::error::Error + std::marker::Send + std::marker::Sync + 'static>>` for `errors::Error`
   = note: required by `std::io::Error::new`

#2

You’ll have to downgrade to error-chain 0.8 - https://github.com/brson/error-chain/pull/110