use std::env;
use std::ffi::OsStr;
use crate::consts::BACKTRACE;
use crate::consts::LIB_BACKTRACE;
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum Verbosity {
#[default]
Minimal,
Medium,
Full,
}
impl Verbosity {
fn decode(thing: &[u8]) -> Option<Self> {
Some(match thing {
b"0" => Verbosity::Minimal,
b"1" => Verbosity::Medium,
b"full" => Verbosity::Full,
_ => return None,
})
}
pub fn error() -> Option<Self> {
env::var_os(LIB_BACKTRACE)
.or_else(|| env::var_os(BACKTRACE))
.as_deref()
.map(OsStr::as_encoded_bytes)
.and_then(Self::decode)
}
pub fn panic() -> Option<Self> {
env::var_os(BACKTRACE)
.as_deref()
.map(OsStr::as_encoded_bytes)
.and_then(Self::decode)
}
#[allow(unused)]
pub(crate) fn as_env(self) -> &'static str {
match self {
Self::Minimal => "0",
Self::Medium => "1",
Self::Full => "full",
}
}
}