mirror of
https://github.com/TECHNOFAB11/aerosol.git
synced 2025-12-11 23:50:07 +01:00
Merge pull request #3 from bradfier/use-std-err
Use anyhow::Error in place of Failure
This commit is contained in:
commit
a117792572
4 changed files with 8 additions and 15 deletions
|
|
@ -9,4 +9,4 @@ license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tt-call = "1.0"
|
tt-call = "1.0"
|
||||||
failure = "0.1"
|
anyhow = "1"
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ macro_rules! private_define_context {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
fn new($($field: $t,)*) -> Result<Self, $crate::failure::Error> {
|
fn new($($field: $t,)*) -> Result<Self, anyhow::Error> {
|
||||||
$(
|
$(
|
||||||
let $auto_field = <$factory as $crate::Factory<_>>::build(($($f_args.clone(),)*))?;
|
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 std::sync::Arc;
|
||||||
/// use failure;
|
|
||||||
///
|
///
|
||||||
/// #[derive(Debug)]
|
/// #[derive(Debug)]
|
||||||
/// struct Foo;
|
/// struct Foo;
|
||||||
|
|
@ -249,7 +248,7 @@ macro_rules! private_define_context {
|
||||||
/// struct FooFactory;
|
/// struct FooFactory;
|
||||||
/// impl aerosol::Factory for FooFactory {
|
/// impl aerosol::Factory for FooFactory {
|
||||||
/// type Object = Arc<Foo>;
|
/// type Object = Arc<Foo>;
|
||||||
/// fn build(_: ()) -> Result<Arc<Foo>, failure::Error> { Ok(Arc::new(Foo)) }
|
/// fn build(_: ()) -> Result<Arc<Foo>, anyhow::Error> { Ok(Arc::new(Foo)) }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// aerosol::define_context!(
|
/// aerosol::define_context!(
|
||||||
|
|
|
||||||
13
src/lib.rs
13
src/lib.rs
|
|
@ -32,7 +32,6 @@
|
||||||
//! #![recursion_limit="128"]
|
//! #![recursion_limit="128"]
|
||||||
//! use std::sync::Arc;
|
//! use std::sync::Arc;
|
||||||
//! use std::fmt::Debug;
|
//! use std::fmt::Debug;
|
||||||
//! use failure;
|
|
||||||
//!
|
//!
|
||||||
//! // We will depend on some kind of logger
|
//! // We will depend on some kind of logger
|
||||||
//! trait Logger: Debug {
|
//! trait Logger: Debug {
|
||||||
|
|
@ -52,7 +51,7 @@
|
||||||
//! struct StdoutLoggerFactory;
|
//! struct StdoutLoggerFactory;
|
||||||
//! impl aerosol::Factory for StdoutLoggerFactory {
|
//! impl aerosol::Factory for StdoutLoggerFactory {
|
||||||
//! type Object = Arc<Logger>;
|
//! type Object = Arc<Logger>;
|
||||||
//! fn build(_: ()) -> Result<Arc<Logger>, failure::Error> {
|
//! fn build(_: ()) -> Result<Arc<Logger>, anyhow::Error> {
|
||||||
//! Ok(Arc::new(StdoutLogger))
|
//! 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.
|
//! See the individual macro documentation for more details.
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub extern crate tt_call;
|
pub extern crate tt_call;
|
||||||
#[doc(hidden)]
|
|
||||||
pub extern crate failure;
|
|
||||||
|
|
||||||
mod join;
|
mod join;
|
||||||
mod parse;
|
mod parse;
|
||||||
|
|
@ -120,7 +115,7 @@ pub trait Provide<T> {
|
||||||
/// constructing implementations of dependencies.
|
/// constructing implementations of dependencies.
|
||||||
pub trait Factory<Args=()> {
|
pub trait Factory<Args=()> {
|
||||||
type Object;
|
type Object;
|
||||||
fn build(args: Args) -> Result<Self::Object, failure::Error>;
|
fn build(args: Args) -> Result<Self::Object, anyhow::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows cloning a context whilst replacing one dependency
|
/// Allows cloning a context whilst replacing one dependency
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
extern crate aerosol;
|
extern crate aerosol;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tt_call;
|
extern crate tt_call;
|
||||||
extern crate failure;
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! tt_debug2 {
|
macro_rules! tt_debug2 {
|
||||||
|
|
@ -40,7 +39,7 @@ struct Bar;
|
||||||
|
|
||||||
impl aerosol::Factory<(Bar,)> for FooFactory {
|
impl aerosol::Factory<(Bar,)> for FooFactory {
|
||||||
type Object = Foo;
|
type Object = Foo;
|
||||||
fn build(_: (Bar,)) -> Result<Foo, failure::Error> { Ok(Foo) }
|
fn build(_: (Bar,)) -> Result<Foo, anyhow::Error> { Ok(Foo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
aerosol::define_context!(
|
aerosol::define_context!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue