diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-09 11:42:45 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-09 18:09:50 +0100 |
commit | 391a4b92c977cd64dfd131f3e29b0bc8d756d064 (patch) | |
tree | b5b96ff935853cef9ee22e01890c248a791e724e /openpgp-ffi/src/error.rs | |
parent | 58d662c6d37dd1b0dccd4d0ce30290b8ede408e9 (diff) |
Switch from failure to anyhow.
- Use the anyhow crate instead of failure to implement the dynamic
side of our error handling. anyhow::Error derefs to dyn
std::error::Error, allowing better interoperability with other
stdlib-based error handling libraries.
- Fixes #444.
Diffstat (limited to 'openpgp-ffi/src/error.rs')
-rw-r--r-- | openpgp-ffi/src/error.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 01e4ed44..5b2bc06d 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -1,6 +1,5 @@ //! Maps various errors to status codes. -use failure; use std::io; use libc::c_char; @@ -11,14 +10,14 @@ use crate::RefRaw; /// Complex errors. /// -/// This wraps [`failure::Error`]s. +/// This wraps [`anyhow::Error`]s. /// -/// [`failure::Error`]: https://docs.rs/failure/0.1.5/failure/struct.Error.html +/// [`anyhow::Error`]: https://docs.rs/failure/0.1.5/failure/struct.Error.html #[crate::ffi_wrapper_type(prefix = "pgp_", derive = "Display")] -pub struct Error(failure::Error); +pub struct Error(anyhow::Error); -impl<T> From<failure::Fallible<T>> for Status { - fn from(f: failure::Fallible<T>) -> crate::error::Status { +impl<T> From<anyhow::Result<T>> for Status { + fn from(f: anyhow::Result<T>) -> crate::error::Status { match f { Ok(_) => crate::error::Status::Success, Err(e) => crate::error::Status::from(&e), @@ -26,7 +25,7 @@ impl<T> From<failure::Fallible<T>> for Status { } } -impl crate::MoveResultIntoRaw<crate::error::Status> for ::failure::Fallible<()> +impl crate::MoveResultIntoRaw<crate::error::Status> for ::anyhow::Result<()> { fn move_into_raw(self, errp: Option<&mut *mut crate::error::Error>) -> crate::error::Status { @@ -210,8 +209,8 @@ pub extern "C" fn pgp_status_to_string(status: Status) -> *const c_char { }.as_bytes().as_ptr() as *const c_char } -impl<'a> From<&'a failure::Error> for Status { - fn from(e: &'a failure::Error) -> Self { +impl<'a> From<&'a anyhow::Error> for Status { + fn from(e: &'a anyhow::Error) -> Self { if let Some(e) = e.downcast_ref::<openpgp::Error>() { return match e { &openpgp::Error::InvalidArgument(_) => |