Skip to content
Myr

Merge pull request #28 from dtolnay/from

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by David Tolnay · committed by GitHub · parents 3570a5e, b961f3a · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−1 removed

  • tests:+10 added−1 removed
  • other:+6 added−0 removed

2 files+16 added−1 removed

modified:src/error.rs+6 added
570 unmodified lines
571 }572 }573}574575impl From<Error> for Box<dyn StdError + 'static> {576 fn from(error: Error) -> Self {577 Box::<dyn StdError + Send + Sync>::from(error)578 }579}580581/// Iterator of a chain of source errors.582///583/// This type is the iterator returned by [`Error::chain`].584///
28 unmodified lines
modified:tests/test_convert.rs+10 added-1 removed
1mod drop;23use self::drop::DetectDrop;4use anyhow::Error;4use anyhow::{Error, Result};5use std::error::Error as StdError;6use std::sync::atomic::AtomicBool;7use std::sync::atomic::Ordering::SeqCst;8use std::sync::Arc;
6 unmodified lines
15 assert_eq!("oh no!", box_dyn.to_string());16 drop(box_dyn);17 assert!(has_dropped.load(SeqCst));18}1920#[test]21fn test_question_mark() -> Result<(), Box<dyn StdError>> {22 fn f() -> Result<()> {23 Ok(())24 }25 f()?;26 Ok(())27}