Rename ContextElem to Detail
This commit is contained in:
parent
639e5835e4
commit
457328945c
|
@ -20,13 +20,13 @@ impl fmt::Display for Context {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
|
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
|
||||||
pub(crate) enum ContextInner {
|
pub(crate) enum ContextInner {
|
||||||
Elem(ContextElem),
|
Elem(Detail),
|
||||||
Compound(Vec<ContextElem>),
|
Compound(Vec<Detail>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
|
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
|
||||||
pub(crate) enum ContextElem {
|
pub(crate) enum Detail {
|
||||||
Str(&'static str),
|
Str(&'static str),
|
||||||
String(String),
|
String(String),
|
||||||
Location(Location<'static>),
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Str(s) => f.write_str(s),
|
Self::Str(s) => f.write_str(s),
|
||||||
|
@ -138,14 +138,14 @@ impl IntoContext for Context {
|
||||||
impl IntoContext for String {
|
impl IntoContext for String {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_context(self) -> Context {
|
fn into_context(self) -> Context {
|
||||||
Context(ContextInner::Elem(ContextElem::String(self)))
|
Context(ContextInner::Elem(Detail::String(self)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoContext for &'static str {
|
impl IntoContext for &'static str {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_context(self) -> Context {
|
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> {
|
impl IntoContext for Location<'static> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_context(self) -> Context {
|
fn into_context(self) -> Context {
|
||||||
Context(ContextInner::Elem(ContextElem::Location(self)))
|
Context(ContextInner::Elem(Detail::Location(self)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::panic::Location;
|
use std::panic::Location;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{How, IntoContext};
|
use crate::{How, IntoContext, Context, ContextInner, Detail};
|
||||||
use crate::context::*;
|
#[cfg(feature = "backtrace")]
|
||||||
|
use crate::context::Backtrace;
|
||||||
|
|
||||||
pub trait Explain {
|
pub trait Explain {
|
||||||
type Output;
|
type Output;
|
||||||
|
@ -19,7 +20,7 @@ impl Explain for How {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn context(mut self, context: impl IntoContext) -> Self {
|
fn context(mut self, context: impl IntoContext) -> Self {
|
||||||
let mut context = context.into_context();
|
let mut context = context.into_context();
|
||||||
let loc = ContextElem::Location(*Location::caller());
|
let loc = Detail::Location(*Location::caller());
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
let bt = {
|
let bt = {
|
||||||
use std::backtrace::BacktraceStatus::*;
|
use std::backtrace::BacktraceStatus::*;
|
||||||
|
@ -29,7 +30,7 @@ impl Explain for How {
|
||||||
Unsupported => Backtrace::Unsupported,
|
Unsupported => Backtrace::Unsupported,
|
||||||
status => Backtrace::Other(status, bt.to_string()),
|
status => Backtrace::Other(status, bt.to_string()),
|
||||||
};
|
};
|
||||||
ContextElem::Backtrace(bt)
|
Detail::Backtrace(bt)
|
||||||
};
|
};
|
||||||
match context.0 {
|
match context.0 {
|
||||||
ContextInner::Elem(elem) => {
|
ContextInner::Elem(elem) => {
|
||||||
|
@ -68,7 +69,7 @@ where
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
// TODO: specialize on Send + Sync at runtime or compile time (possibly via
|
// TODO: specialize on Send + Sync at runtime or compile time (possibly via
|
||||||
// specialization)
|
// 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()),
|
Err(e) => How::new(e.to_string()),
|
||||||
}
|
}
|
||||||
.context(c)
|
.context(c)
|
||||||
|
@ -88,7 +89,7 @@ where
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn context(self, context: impl IntoContext) -> Self::Output {
|
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)
|
.context(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#![feature(doc_auto_cfg)]
|
#![feature(doc_auto_cfg)]
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
|
pub(crate) use context::{ContextInner, Detail};
|
||||||
pub use context::{Context, IntoContext};
|
pub use context::{Context, IntoContext};
|
||||||
|
|
||||||
mod report;
|
mod report;
|
||||||
|
|
Loading…
Reference in New Issue