Rename ContextElem to Detail

This commit is contained in:
Michael Pfaff 2023-06-29 11:55:21 -04:00
parent 639e5835e4
commit 457328945c
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
3 changed files with 15 additions and 13 deletions

View File

@ -20,13 +20,13 @@ impl fmt::Display for Context {
#[derive(Debug)]
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
pub(crate) enum ContextInner {
Elem(ContextElem),
Compound(Vec<ContextElem>),
Elem(Detail),
Compound(Vec<Detail>),
}
#[derive(Debug)]
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
pub(crate) enum ContextElem {
pub(crate) enum Detail {
Str(&'static str),
String(String),
Location(Location<'static>),
@ -69,7 +69,7 @@ impl fmt::Display for ContextInner {
}
}
impl fmt::Display for ContextElem {
impl fmt::Display for Detail {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Str(s) => f.write_str(s),
@ -138,14 +138,14 @@ impl IntoContext for Context {
impl IntoContext for String {
#[inline(always)]
fn into_context(self) -> Context {
Context(ContextInner::Elem(ContextElem::String(self)))
Context(ContextInner::Elem(Detail::String(self)))
}
}
impl IntoContext for &'static str {
#[inline(always)]
fn into_context(self) -> Context {
Context(ContextInner::Elem(ContextElem::Str(self)))
Context(ContextInner::Elem(Detail::Str(self)))
}
}
@ -169,7 +169,7 @@ impl<'a> IntoContext for &'a Location<'static> {
impl IntoContext for Location<'static> {
#[inline]
fn into_context(self) -> Context {
Context(ContextInner::Elem(ContextElem::Location(self)))
Context(ContextInner::Elem(Detail::Location(self)))
}
}

View File

@ -1,8 +1,9 @@
use std::panic::Location;
use std::sync::Arc;
use crate::{How, IntoContext};
use crate::context::*;
use crate::{How, IntoContext, Context, ContextInner, Detail};
#[cfg(feature = "backtrace")]
use crate::context::Backtrace;
pub trait Explain {
type Output;
@ -19,7 +20,7 @@ impl Explain for How {
#[inline]
fn context(mut self, context: impl IntoContext) -> Self {
let mut context = context.into_context();
let loc = ContextElem::Location(*Location::caller());
let loc = Detail::Location(*Location::caller());
#[cfg(feature = "backtrace")]
let bt = {
use std::backtrace::BacktraceStatus::*;
@ -29,7 +30,7 @@ impl Explain for How {
Unsupported => Backtrace::Unsupported,
status => Backtrace::Other(status, bt.to_string()),
};
ContextElem::Backtrace(bt)
Detail::Backtrace(bt)
};
match context.0 {
ContextInner::Elem(elem) => {
@ -68,7 +69,7 @@ where
Ok(e) => e,
// TODO: specialize on Send + Sync at runtime or compile time (possibly via
// specialization)
//Err(e) => How::new(Context(ContextInner::Elem(ContextElem::Error(Arc::new(e))))),
//Err(e) => How::new(Context(ContextInner::Elem(Detail::Error(Arc::new(e))))),
Err(e) => How::new(e.to_string()),
}
.context(c)
@ -88,7 +89,7 @@ where
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output {
How::new(Context(ContextInner::Elem(ContextElem::Error(self))))
How::new(Context(ContextInner::Elem(Detail::Error(self))))
.context(context)
}
}

View File

@ -3,6 +3,7 @@
#![feature(doc_auto_cfg)]
mod context;
pub(crate) use context::{ContextInner, Detail};
pub use context::{Context, IntoContext};
mod report;