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
use crate::{validation::Error, Ref, Value};
use tracing::error;
/// Defines the behavior for a snapshot of configuration options.
#[cfg_attr(feature = "async", maybe_impl::traits(Send, Sync))]
pub trait Snapshot<T: Value> {
/// Gets the default, unnamed configuration options.
fn get(&self) -> Result<Ref<T>, Error> {
self.get_named("")
}
/// Gets the default, unnamed configuration options.
///
/// # Remarks
///
/// This function panics if the configuration options could not be successfully retrieved.
fn get_unchecked(&self) -> Ref<T> {
match self.get_named("") {
Ok(value) => value,
Err(error) => {
error!("{error:?}");
panic!("{}", error)
}
}
}
/// Gets the configuration options with the specified name.
///
/// # Arguments
///
/// * `name` - The optional name of the options to retrieve
fn get_named(&self, name: &str) -> Result<Ref<T>, Error>;
/// Gets the configuration options with the specified name.
///
/// # Arguments
///
/// * `name` - The optional name of the options to retrieve
///
/// # Remarks
///
/// This function panics if the configuration options could not be successfully retrieved.
fn get_named_unchecked(&self, name: &str) -> Ref<T> {
match self.get_named(name) {
Ok(value) => value,
Err(error) => {
error!("[{name}] {error:?}");
panic!("[{name}] {}", error)
}
}
}
}