Run `cargo fmt`
This commit is contained in:
parent
fb08be31d4
commit
cab16130f7
|
@ -1,16 +1,19 @@
|
||||||
use std::borrow::Cow;
|
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
use std::backtrace::BacktraceStatus;
|
use std::backtrace::BacktraceStatus;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::panic::Location;
|
use std::panic::Location;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::ReportOpts;
|
|
||||||
use crate::report::report_write;
|
use crate::report::report_write;
|
||||||
|
use crate::ReportOpts;
|
||||||
|
|
||||||
/// Provides context furthering the explanation of *how* you got to an error.
|
/// Provides context furthering the explanation of *how* you got to an error.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(any(feature = "arc-backtrace", feature = "clone-with-caveats"), derive(Clone))]
|
#[cfg_attr(
|
||||||
|
any(feature = "arc-backtrace", feature = "clone-with-caveats"),
|
||||||
|
derive(Clone)
|
||||||
|
)]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub(crate) detail: Detail,
|
pub(crate) detail: Detail,
|
||||||
pub(crate) extra: Vec<Detail>,
|
pub(crate) extra: Vec<Detail>,
|
||||||
|
@ -18,7 +21,10 @@ pub struct Context {
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
pub(crate) fn new(detail: Detail) -> Self {
|
pub(crate) fn new(detail: Detail) -> Self {
|
||||||
Self { detail, extra: Vec::new() }
|
Self {
|
||||||
|
detail,
|
||||||
|
extra: Vec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detail(&self) -> &Detail {
|
pub fn detail(&self) -> &Detail {
|
||||||
|
@ -65,7 +71,10 @@ impl fmt::Display for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(any(feature = "arc-backtrace", feature = "clone-with-caveats"), derive(Clone))]
|
#[cfg_attr(
|
||||||
|
any(feature = "arc-backtrace", feature = "clone-with-caveats"),
|
||||||
|
derive(Clone)
|
||||||
|
)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Detail {
|
pub enum Detail {
|
||||||
Str(&'static str),
|
Str(&'static str),
|
||||||
|
@ -97,7 +106,10 @@ pub struct PrivateError(pub(crate) Arc<dyn std::error::Error + Send + Sync>);
|
||||||
|
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(any(feature = "arc-backtrace", feature = "clone-with-caveats"), derive(Clone))]
|
#[cfg_attr(
|
||||||
|
any(feature = "arc-backtrace", feature = "clone-with-caveats"),
|
||||||
|
derive(Clone)
|
||||||
|
)]
|
||||||
pub struct PrivateBacktrace(pub(crate) Backtrace);
|
pub struct PrivateBacktrace(pub(crate) Backtrace);
|
||||||
|
|
||||||
// will be replaced with std::backtrace::Backtrace if and when it is Clone
|
// will be replaced with std::backtrace::Backtrace if and when it is Clone
|
||||||
|
@ -113,12 +125,16 @@ pub(crate) enum Backtrace {
|
||||||
Other(std::backtrace::Backtrace),
|
Other(std::backtrace::Backtrace),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "backtrace", feature = "clone-with-caveats", not(feature = "arc-backtrace")))]
|
#[cfg(all(
|
||||||
|
feature = "backtrace",
|
||||||
|
feature = "clone-with-caveats",
|
||||||
|
not(feature = "arc-backtrace")
|
||||||
|
))]
|
||||||
impl Clone for Backtrace {
|
impl Clone for Backtrace {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Self::Unsupported => Self::Unsupported,
|
Self::Unsupported => Self::Unsupported,
|
||||||
_ => Self::Disabled
|
_ => Self::Disabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,9 +146,13 @@ impl fmt::Display for Detail {
|
||||||
Self::String(s) => f.write_str(s),
|
Self::String(s) => f.write_str(s),
|
||||||
Self::Location(l) => write!(f, "at {l}"),
|
Self::Location(l) => write!(f, "at {l}"),
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
Self::Backtrace(PrivateBacktrace(Backtrace::Unsupported)) => f.write_str("I'd like to show you a backtrace,\n but it's not supported on your platform"),
|
Self::Backtrace(PrivateBacktrace(Backtrace::Unsupported)) => f.write_str(
|
||||||
|
"I'd like to show you a backtrace,\n but it's not supported on your platform",
|
||||||
|
),
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
Self::Backtrace(PrivateBacktrace(Backtrace::Disabled)) => f.write_str("If you'd like a backtrace,\n try again with RUST_BACKTRACE=1"),
|
Self::Backtrace(PrivateBacktrace(Backtrace::Disabled)) => {
|
||||||
|
f.write_str("If you'd like a backtrace,\n try again with RUST_BACKTRACE=1")
|
||||||
|
}
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
Self::Backtrace(PrivateBacktrace(Backtrace::Other(bt))) => {
|
Self::Backtrace(PrivateBacktrace(Backtrace::Other(bt))) => {
|
||||||
f.write_str(if bt.status() == BacktraceStatus::Captured {
|
f.write_str(if bt.status() == BacktraceStatus::Captured {
|
||||||
|
@ -141,7 +161,7 @@ impl fmt::Display for Detail {
|
||||||
"I can't tell if backtraces are working,\n but I'll give it a go:\n"
|
"I can't tell if backtraces are working,\n but I'll give it a go:\n"
|
||||||
})?;
|
})?;
|
||||||
write!(f, "{}", bt)
|
write!(f, "{}", bt)
|
||||||
},
|
}
|
||||||
Self::Error(PrivateError(e)) => e.fmt(f),
|
Self::Error(PrivateError(e)) => e.fmt(f),
|
||||||
Self::Context(c) => c.fmt(f),
|
Self::Context(c) => c.fmt(f),
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@ impl ReportOpts {
|
||||||
|
|
||||||
macro_rules! report_write {
|
macro_rules! report_write {
|
||||||
($f:expr, $opts:expr, $msg:literal$(, $($tt:tt)+)?) => {
|
($f:expr, $opts:expr, $msg:literal$(, $($tt:tt)+)?) => {
|
||||||
<::std::fmt::Arguments<'_> as $crate::Report>::fmt(&::std::format_args!($msg$(, $($tt)+)?), $f, $opts)
|
<::std::fmt::Arguments<'_> as $crate::Report>::fmt(&::std::format_args!(
|
||||||
|
$msg$(, $($tt)+)?), $f, $opts
|
||||||
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use report_write;
|
pub(crate) use report_write;
|
||||||
|
@ -46,7 +48,9 @@ fn write_indent(n: usize, f: &mut impl Write) -> std::fmt::Result {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Report` should format the output in a manner suitable for debugging, similar to [`std::fmt::Debug`] in terms of detail, but similar to [`std::fmt::Display`] in terms of readability. The options passed to [`Self::fmt`] must be respected by all implementations.
|
/// `Report` should format the output in a manner suitable for debugging, similar to
|
||||||
|
/// [`std::fmt::Debug`] in terms of detail, but similar to [`std::fmt::Display`] in terms of
|
||||||
|
/// readability. The options passed to [`Self::fmt`] must be respected by all implementations.
|
||||||
pub trait Report {
|
pub trait Report {
|
||||||
/// Formats the value using the given formatter and options.
|
/// Formats the value using the given formatter and options.
|
||||||
fn fmt(&self, f: &mut impl Write, opts: &ReportOpts) -> std::fmt::Result;
|
fn fmt(&self, f: &mut impl Write, opts: &ReportOpts) -> std::fmt::Result;
|
||||||
|
|
Loading…
Reference in New Issue