From ec3ea2425f7273bf9ac0fb31f30dabad75953db0 Mon Sep 17 00:00:00 2001 From: Richard Bradfield Date: Tue, 2 Jun 2020 10:25:22 +0100 Subject: [PATCH] Use anyhow::Error in place of Failure Since Failure is now deprecated, and Rust's own std::error::Error trait doesn't preserve a backtrace on Stable, if we want to move to a supported library the most obvious successor is Anyhow. --- Cargo.toml | 2 +- src/context.rs | 5 ++--- src/lib.rs | 13 ++++--------- src/main.rs | 3 +-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6204c3b..b750582 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ license = "MIT OR Apache-2.0" [dependencies] tt-call = "1.0" -failure = "0.1" +anyhow = "1" diff --git a/src/context.rs b/src/context.rs index 83a55a4..734cde9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -34,7 +34,7 @@ macro_rules! private_define_context { } impl $name { - fn new($($field: $t,)*) -> Result { + fn new($($field: $t,)*) -> Result { $( let $auto_field = <$factory as $crate::Factory<_>>::build(($($f_args.clone(),)*))?; )* @@ -239,7 +239,6 @@ macro_rules! private_define_context { /// /// ``` /// use std::sync::Arc; -/// use failure; /// /// #[derive(Debug)] /// struct Foo; @@ -249,7 +248,7 @@ macro_rules! private_define_context { /// struct FooFactory; /// impl aerosol::Factory for FooFactory { /// type Object = Arc; -/// fn build(_: ()) -> Result, failure::Error> { Ok(Arc::new(Foo)) } +/// fn build(_: ()) -> Result, anyhow::Error> { Ok(Arc::new(Foo)) } /// } /// /// aerosol::define_context!( diff --git a/src/lib.rs b/src/lib.rs index d826c82..244b58c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,6 @@ //! #![recursion_limit="128"] //! use std::sync::Arc; //! use std::fmt::Debug; -//! use failure; //! //! // We will depend on some kind of logger //! trait Logger: Debug { @@ -52,7 +51,7 @@ //! struct StdoutLoggerFactory; //! impl aerosol::Factory for StdoutLoggerFactory { //! type Object = Arc; -//! fn build(_: ()) -> Result, failure::Error> { +//! fn build(_: ()) -> Result, anyhow::Error> { //! Ok(Arc::new(StdoutLogger)) //! } //! } @@ -87,19 +86,15 @@ //! } //! ); //! -//! fn main() { -//! let context = AppContext::new().unwrap(); +//! let context = AppContext::new().unwrap(); //! -//! run_app(context, 4); -//! } +//! run_app(context, 4); //! ``` //! //! See the individual macro documentation for more details. #[doc(hidden)] pub extern crate tt_call; -#[doc(hidden)] -pub extern crate failure; mod join; mod parse; @@ -120,7 +115,7 @@ pub trait Provide { /// constructing implementations of dependencies. pub trait Factory { type Object; - fn build(args: Args) -> Result; + fn build(args: Args) -> Result; } /// Allows cloning a context whilst replacing one dependency diff --git a/src/main.rs b/src/main.rs index 17a9dab..5bc5b8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ extern crate aerosol; #[macro_use] extern crate tt_call; -extern crate failure; #[macro_export] macro_rules! tt_debug2 { @@ -40,7 +39,7 @@ struct Bar; impl aerosol::Factory<(Bar,)> for FooFactory { type Object = Foo; - fn build(_: (Bar,)) -> Result { Ok(Foo) } + fn build(_: (Bar,)) -> Result { Ok(Foo) } } aerosol::define_context!(