Add a Chain::new constructor

This commit is contained in:
David Tolnay 2019-11-22 16:34:50 -08:00
parent 2c88164b5b
commit ca2b8b9bb0
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 9 additions and 6 deletions

View File

@ -13,6 +13,14 @@ pub(crate) enum ChainState<'a> {
},
}
impl<'a> Chain<'a> {
pub fn new(head: &'a (dyn StdError + 'static)) -> Self {
Chain {
state: ChainState::Linked { next: Some(head) },
}
}
}
impl<'a> Iterator for Chain<'a> {
type Item = &'a (dyn StdError + 'static);

View File

@ -1,5 +1,4 @@
use crate::backtrace::Backtrace;
use crate::chain::ChainState;
use crate::{Chain, Error};
use std::any::TypeId;
use std::error::Error as StdError;
@ -722,11 +721,7 @@ impl ErrorImpl<()> {
}
pub(crate) fn chain(&self) -> Chain {
Chain {
state: ChainState::Linked {
next: Some(self.error()),
},
}
Chain::new(self.error())
}
}