1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::env;
use std::ffi::OsStr;
use crate::consts::BACKTRACE;
use crate::consts::LIB_BACKTRACE;
/// Setting for backtrace details
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
#[non_exhaustive]
pub enum Verbosity {
/// No backtrace will be collected
#[default]
Minimal,
/// Backtrace will be filtered (influenced by registered [`FrameFilter`](crate::FrameFilter)s)
Medium,
/// Backtrace will be shown in full
Full,
}
impl Verbosity {
const fn decode(thing: &[u8]) -> Self {
#[allow(clippy::match_same_arms)]
match thing {
b"0" => Verbosity::Minimal,
b"1" => Verbosity::Medium,
b"full" => Verbosity::Full,
_ => Verbosity::Medium,
}
}
/// Retrieves [`Verbosity`] that should be used by errors (based on environment variables)
#[must_use]
pub fn error() -> Option<Self> {
env::var_os(LIB_BACKTRACE)
.or_else(|| env::var_os(BACKTRACE))
.as_deref()
.map(OsStr::as_encoded_bytes)
.map(Self::decode)
}
/// Retrieves [`Verbosity`] that should be used by panics (based on environment variables)
#[must_use]
pub fn panic() -> Option<Self> {
env::var_os(BACKTRACE)
.as_deref()
.map(OsStr::as_encoded_bytes)
.map(Self::decode)
}
/// Shows environment name corresponding to provided [`Verbosity`]
#[must_use]
#[inline]
pub const fn env(self) -> &'static str {
match self {
Self::Minimal => "0",
Self::Medium => "1",
Self::Full => "full",
}
}
}