Trait Config

Source
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§

Source

fn keys(&self, section: &str) -> Vec<Text>

Get config names in the given section. Sorted by insertion order.

Source

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.
Source

fn sections(&self) -> Cow<'_, [Text]>

Get config sections.

Source

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Get the sources of a config.

Source

fn layer_name(&self) -> Text

The name of the current layer.

Provided Methods§

Source

fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text>

Keys with the given prefix.

Source

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.

Source

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.

Source

fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>

Get on-disk files loaded for this Config.

Source

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.

Source

fn pinned(&self) -> Vec<(Text, Text, Vec<ValueSource>)>

Implementations on Foreign Types§

Source§

impl Config for BTreeMap<&str, &str>

Source§

fn keys(&self, section: &str) -> Vec<Text>

Source§

fn sections(&self) -> Cow<'_, [Text]>

Source§

fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>

Source§

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Source§

fn layer_name(&self) -> Text

Source§

impl Config for BTreeMap<String, String>

Source§

fn keys(&self, section: &str) -> Vec<Text>

Source§

fn sections(&self) -> Cow<'_, [Text]>

Source§

fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>

Source§

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Source§

fn layer_name(&self) -> Text

Source§

impl<'a, T: 'a + Config + ?Sized> Config for &'a T
where &'a T: Send + Sync,

Source§

fn keys(&self, section: &str) -> Vec<Text>

Source§

fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text>

Source§

fn get(&self, section: &str, name: &str) -> Option<Text>

Source§

fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>

Source§

fn get_nonempty(&self, section: &str, name: &str) -> Option<Text>

Source§

fn sections(&self) -> Cow<'_, [Text]>

Source§

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Source§

fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>

Source§

fn layers(&self) -> Vec<Arc<dyn Config>>

Source§

fn layer_name(&self) -> Text

Source§

fn pinned(&self) -> Vec<(Text, Text, Vec<ValueSource>)>

Source§

impl<T: Config + ?Sized> Config for Box<T>
where Box<T>: Send + Sync,

Source§

fn keys(&self, section: &str) -> Vec<Text>

Source§

fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text>

Source§

fn get(&self, section: &str, name: &str) -> Option<Text>

Source§

fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>

Source§

fn get_nonempty(&self, section: &str, name: &str) -> Option<Text>

Source§

fn sections(&self) -> Cow<'_, [Text]>

Source§

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Source§

fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>

Source§

fn layers(&self) -> Vec<Arc<dyn Config>>

Source§

fn layer_name(&self) -> Text

Source§

fn pinned(&self) -> Vec<(Text, Text, Vec<ValueSource>)>

Source§

impl<T: Config + ?Sized> Config for Arc<T>
where Arc<T>: Send + Sync,

Source§

fn keys(&self, section: &str) -> Vec<Text>

Source§

fn keys_prefixed(&self, section: &str, prefix: &str) -> Vec<Text>

Source§

fn get(&self, section: &str, name: &str) -> Option<Text>

Source§

fn get_considering_unset( &self, section: &str, name: &str, ) -> Option<Option<Text>>

Source§

fn get_nonempty(&self, section: &str, name: &str) -> Option<Text>

Source§

fn sections(&self) -> Cow<'_, [Text]>

Source§

fn get_sources(&self, section: &str, name: &str) -> Cow<'_, [ValueSource]>

Source§

fn files(&self) -> Cow<'_, [(PathBuf, Option<ContentHash>)]>

Source§

fn layers(&self) -> Vec<Arc<dyn Config>>

Source§

fn layer_name(&self) -> Text

Source§

fn pinned(&self) -> Vec<(Text, Text, Vec<ValueSource>)>

Implementors§