error_stack/fmt/
config.rs

1use crate::fmt::{Charset, ColorMode};
2#[cfg(any(feature = "std", feature = "hooks"))]
3use crate::fmt::{Format, HookContext};
4
5#[cfg(any(feature = "std", feature = "hooks"))]
6pub(crate) struct Config {
7    context: HookContext<()>,
8}
9
10#[cfg(any(feature = "std", feature = "hooks"))]
11impl Config {
12    pub(crate) fn new(color_mode: ColorMode, charset: Charset, alternate: bool) -> Self {
13        let context = HookContext::new(Format::new(alternate, color_mode, charset));
14
15        Self { context }
16    }
17
18    pub(crate) fn load(alternate: bool) -> Self {
19        let color_mode = ColorMode::load();
20        let charset = Charset::load();
21
22        Self::new(color_mode, charset, alternate)
23    }
24
25    pub(crate) fn context<T>(&mut self) -> &mut HookContext<T> {
26        self.context.cast()
27    }
28
29    pub(crate) const fn color_mode(&self) -> ColorMode {
30        self.context.color_mode()
31    }
32
33    pub(crate) const fn charset(&self) -> Charset {
34        self.context.charset()
35    }
36}
37
38#[cfg(not(any(feature = "std", feature = "hooks")))]
39pub(crate) struct Config {
40    color_mode: ColorMode,
41    charset: Charset,
42}
43
44#[cfg(not(any(feature = "std", feature = "hooks")))]
45impl Config {
46    pub(crate) const fn new(color_mode: ColorMode, charset: Charset, _alternate: bool) -> Self {
47        Self {
48            color_mode,
49            charset,
50        }
51    }
52
53    pub(crate) fn load(alternate: bool) -> Self {
54        let color_mode = ColorMode::load();
55        let charset = Charset::load();
56
57        Self::new(color_mode, charset, alternate)
58    }
59
60    pub(crate) const fn color_mode(&self) -> ColorMode {
61        self.color_mode
62    }
63
64    pub(crate) const fn charset(&self) -> Charset {
65        self.charset
66    }
67}