Add From<anyhow::Error> for Box<dyn std::error::Error>

This commit is contained in:
David Tolnay 2019-10-19 17:44:32 -04:00
parent 3570a5ec2c
commit b961f3a594
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 16 additions and 1 deletions

View File

@ -572,6 +572,12 @@ impl From<Error> for Box<dyn StdError + Send + Sync + 'static> {
}
}
impl From<Error> for Box<dyn StdError + 'static> {
fn from(error: Error) -> Self {
Box::<dyn StdError + Send + Sync>::from(error)
}
}
/// Iterator of a chain of source errors.
///
/// This type is the iterator returned by [`Error::chain`].

View File

@ -1,7 +1,7 @@
mod drop;
use self::drop::DetectDrop;
use anyhow::Error;
use anyhow::{Error, Result};
use std::error::Error as StdError;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
@ -16,3 +16,12 @@ fn test_convert() {
drop(box_dyn);
assert!(has_dropped.load(SeqCst));
}
#[test]
fn test_question_mark() -> Result<(), Box<dyn StdError>> {
fn f() -> Result<()> {
Ok(())
}
f()?;
Ok(())
}