rename path to trace

This commit is contained in:
Ryan 2022-08-29 05:05:04 -07:00
parent 158eba1d15
commit 8abe8b7ebf

View file

@ -14,7 +14,7 @@ pub struct Error {
#[derive(Debug)] #[derive(Debug)]
struct ErrorInner { struct ErrorInner {
path: Vec<String>, trace: Vec<String>,
cause: Cause, cause: Cause,
} }
@ -30,7 +30,7 @@ impl Error {
pub(crate) fn new_owned(msg: impl Into<Box<str>>) -> Self { pub(crate) fn new_owned(msg: impl Into<Box<str>>) -> Self {
Self { Self {
inner: Box::new(ErrorInner { inner: Box::new(ErrorInner {
path: Vec::new(), trace: Vec::new(),
cause: Cause::Owned(msg.into()), cause: Cause::Owned(msg.into()),
}), }),
} }
@ -39,32 +39,32 @@ impl Error {
pub(crate) fn new_static(msg: &'static str) -> Self { pub(crate) fn new_static(msg: &'static str) -> Self {
Self { Self {
inner: Box::new(ErrorInner { inner: Box::new(ErrorInner {
path: Vec::new(), trace: Vec::new(),
cause: Cause::Static(msg), cause: Cause::Static(msg),
}), }),
} }
} }
pub(crate) fn field(mut self, ctx: impl Into<String>) -> Self { pub(crate) fn field(mut self, ctx: impl Into<String>) -> Self {
self.inner.path.push(ctx.into()); self.inner.trace.push(ctx.into());
self self
} }
pub fn path( pub fn trace(
&self, &self,
) -> impl DoubleEndedIterator<Item = &str> + ExactSizeIterator + FusedIterator + Clone + '_ ) -> impl DoubleEndedIterator<Item = &str> + ExactSizeIterator + FusedIterator + Clone + '_
{ {
self.inner.path.iter().rev().map(|s| s.as_str()) self.inner.trace.iter().rev().map(|s| s.as_str())
} }
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let len = self.inner.path.len(); let len = self.inner.trace.len();
if len > 0 { if len > 0 {
write!(f, "(")?; write!(f, "(")?;
for (i, ctx) in self.path().enumerate() { for (i, ctx) in self.trace().enumerate() {
write!(f, "{ctx}")?; write!(f, "{ctx}")?;
if i != len - 1 { if i != len - 1 {
@ -114,7 +114,7 @@ impl From<io::Error> for Error {
fn from(e: io::Error) -> Self { fn from(e: io::Error) -> Self {
Self { Self {
inner: Box::new(ErrorInner { inner: Box::new(ErrorInner {
path: Vec::new(), trace: Vec::new(),
cause: Cause::Io(e), cause: Cause::Io(e),
}), }),
} }