options/snapshot.rs
1use crate::{validation::Error, Ref, Value};
2use tracing::error;
3
4/// Defines the behavior for a snapshot of configuration options.
5#[cfg_attr(feature = "async", maybe_impl::traits(Send, Sync))]
6pub trait Snapshot<T: Value> {
7 /// Gets the default, unnamed configuration options.
8 fn get(&self) -> Result<Ref<T>, Error> {
9 self.get_named("")
10 }
11
12 /// Gets the default, unnamed configuration options.
13 ///
14 /// # Remarks
15 ///
16 /// This function panics if the configuration options could not be successfully retrieved.
17 fn get_unchecked(&self) -> Ref<T> {
18 match self.get_named("") {
19 Ok(value) => value,
20 Err(error) => {
21 error!("{error:?}");
22 panic!("{}", error)
23 }
24 }
25 }
26
27 /// Gets the configuration options with the specified name.
28 ///
29 /// # Arguments
30 ///
31 /// * `name` - The optional name of the options to retrieve
32 fn get_named(&self, name: &str) -> Result<Ref<T>, Error>;
33
34 /// Gets the configuration options with the specified name.
35 ///
36 /// # Arguments
37 ///
38 /// * `name` - The optional name of the options to retrieve
39 ///
40 /// # Remarks
41 ///
42 /// This function panics if the configuration options could not be successfully retrieved.
43 fn get_named_unchecked(&self, name: &str) -> Ref<T> {
44 match self.get_named(name) {
45 Ok(value) => value,
46 Err(error) => {
47 error!("[{name}] {error:?}");
48 panic!("[{name}] {}", error)
49 }
50 }
51 }
52}