arachnid_cli/
context.rs

1/*
2    Appellation: context <module>
3    Created At: 2026.01.10:16:28:22
4    Contrib: @FL03
5*/
6use crate::config::Settings;
7
8#[derive(
9    Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
10)]
11#[serde(rename_all = "snake_case", deny_unknown_fields)]
12pub struct Context {
13    pub(crate) settings: Settings,
14}
15
16impl Context {
17    /// attempts to build the settings from the configured sources, falling back to the default
18    pub fn new() -> Self {
19        let settings = Settings::build().unwrap_or_default();
20        Self { settings }
21    }
22    /// initialize a new context from the given configuration
23    pub const fn from_config(settings: Settings) -> Self {
24        Self { settings }
25    }
26    /// returns a reference to the [`Settings`] of the current context.
27    pub const fn settings(&self) -> &Settings {
28        &self.settings
29    }
30    /// returns a mutable reference to the [`Settings`] of the current context.
31    pub fn settings_mut(&mut self) -> &mut Settings {
32        &mut self.settings
33    }
34}