mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-10-02 15:26:08 +00:00
Merge pull request #47 from dtolnay/anyhow
Handle anyhow::Error as argument to anyhow!()
This commit is contained in:
commit
cb3c80cca7
@ -45,7 +45,6 @@
|
|||||||
// (&error).anyhow_kind().new(error)
|
// (&error).anyhow_kind().new(error)
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use std::error::Error as StdError;
|
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::{Debug, Display};
|
||||||
|
|
||||||
#[cfg(backtrace)]
|
#[cfg(backtrace)]
|
||||||
@ -80,13 +79,13 @@ pub trait TraitKind: Sized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TraitKind for T where T: StdError + Send + Sync + 'static {}
|
impl<E> TraitKind for E where E: Into<Error> {}
|
||||||
|
|
||||||
impl Trait {
|
impl Trait {
|
||||||
pub fn new<E>(self, error: E) -> Error
|
pub fn new<E>(self, error: E) -> Error
|
||||||
where
|
where
|
||||||
E: StdError + Send + Sync + 'static,
|
E: Into<Error>,
|
||||||
{
|
{
|
||||||
Error::from_std(error, backtrace!())
|
error.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,3 +53,10 @@ fn test_io_source() {
|
|||||||
let error = anyhow!(TestError::Io(io));
|
let error = anyhow!(TestError::Io(io));
|
||||||
assert_eq!("oh no!", error.source().unwrap().to_string());
|
assert_eq!("oh no!", error.source().unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_anyhow_from_anyhow() {
|
||||||
|
let error = anyhow!("oh no!").context("context");
|
||||||
|
let error = anyhow!(error);
|
||||||
|
assert_eq!("oh no!", error.source().unwrap().to_string());
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user