pub trait Config: Send + Sync {
// Required methods
fn keys(&self, section: &str) -> Vec<Text> ⓘ;
fn get_considering_unset(
&self,
section: &str,
name: &str,
) -> Option<Option<Text>>;
fn sections(&self) -> Cow<'_, [Text]>;
fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>;
fn layer_name(&self) -> Text;
// Provided methods
fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text> ⓘ { ... }
fn get(&self, section: &str, name: &str) -> Option<Text> { ... }
fn get_nonempty(&self, section: &str, name: &str) -> Option<Text> { ... }
fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]> { ... }
fn layers(&self) -> Vec<Arc<dyn Config>> { ... }
fn pinned(&self) -> Vec<(Text, Text, Vec<ValueSource>)> { ... }
}Expand description
Readable config. This can be used as a trait object.
Required Methods§
Sourcefn keys(&self, section: &str) -> Vec<Text> ⓘ
fn keys(&self, section: &str) -> Vec<Text> ⓘ
Get config names in the given section. Sorted by insertion order.
Sourcefn get_considering_unset(
&self,
section: &str,
name: &str,
) -> Option<Option<Text>>
fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>
Similar to get, but can represent “%unset” result.
None: not set or unset.Some(None): unset.Some(Some(value)): set.
Sourcefn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>
fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>
Get the sources of a config.
Sourcefn layer_name(&self) -> Text
fn layer_name(&self) -> Text
The name of the current layer.
Provided Methods§
Sourcefn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text> ⓘ
fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text> ⓘ
Keys with the given prefix.
Sourcefn get(&self, section: &str, name: &str) -> Option<Text>
fn get(&self, section: &str, name: &str) -> Option<Text>
Get config value for a given config.
Return None if the config item does not exist or is unset.
Sourcefn get_nonempty(&self, section: &str, name: &str) -> Option<Text>
fn get_nonempty(&self, section: &str, name: &str) -> Option<Text>
Get a nonempty config value for a given config.
Return None if the config item does not exist, is unset or is empty str.
Sourcefn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>
fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>
Get on-disk files loaded for this Config.
Sourcefn layers(&self) -> Vec<Arc<dyn Config>>
fn layers(&self) -> Vec<Arc<dyn Config>>
Break the config into (immutable) layers.
If returns an empty list, then the config object is considered atomic.
If returns a list, then those are considered “sub”-configs that this config will consider. The order matters. Config with a larger index overrides configs with smaller indexes. Note the combination of all sub-configs might not be equivalent to the “self” config, since there might be some overrides.