pub struct StackedConfig { /* private fields */ }
Expand description
Stack of configuration layers which can be merged as needed.
A StackedConfig
is something like a read-only overlayfs
. Tables and
values are directories and files respectively, and tables are merged across
layers. Tables and values can be addressed by dotted name
paths.
There’s no tombstone notation to remove items from the lower layers.
Beware that arrays of tables are no different than inline arrays. They are values, so are never merged. This might be confusing because they would be merged if two TOML documents are concatenated literally. Avoid using array of tables syntax.
Implementations§
Source§impl StackedConfig
impl StackedConfig
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Creates a stack of configuration layers containing the default variables
referred to by jj-lib
.
Sourcepub fn load_file(
&mut self,
source: ConfigSource,
path: impl Into<PathBuf>,
) -> Result<(), ConfigLoadError>
pub fn load_file( &mut self, source: ConfigSource, path: impl Into<PathBuf>, ) -> Result<(), ConfigLoadError>
Loads config file from the specified path
, inserts it at the position
specified by source
. The file should exist.
Sourcepub fn load_dir(
&mut self,
source: ConfigSource,
path: impl AsRef<Path>,
) -> Result<(), ConfigLoadError>
pub fn load_dir( &mut self, source: ConfigSource, path: impl AsRef<Path>, ) -> Result<(), ConfigLoadError>
Loads config files from the specified directory path
, inserts them at
the position specified by source
. The directory should exist.
Sourcepub fn add_layer(&mut self, layer: impl Into<Arc<ConfigLayer>>)
pub fn add_layer(&mut self, layer: impl Into<Arc<ConfigLayer>>)
Inserts new layer at the position specified by layer.source
.
Sourcepub fn extend_layers<I>(&mut self, layers: I)
pub fn extend_layers<I>(&mut self, layers: I)
Inserts multiple layers at the positions specified by layer.source
.
Sourcepub fn remove_layers(&mut self, source: ConfigSource)
pub fn remove_layers(&mut self, source: ConfigSource)
Removes layers of the specified source
.
Sourcepub fn layers(&self) -> &[Arc<ConfigLayer>]
pub fn layers(&self) -> &[Arc<ConfigLayer>]
Layers sorted by precedence.
Sourcepub fn layers_mut(&mut self) -> &mut [Arc<ConfigLayer>]
pub fn layers_mut(&mut self) -> &mut [Arc<ConfigLayer>]
Mutable references to layers sorted by precedence.
Sourcepub fn layers_for(&self, source: ConfigSource) -> &[Arc<ConfigLayer>]
pub fn layers_for(&self, source: ConfigSource) -> &[Arc<ConfigLayer>]
Layers of the specified source
.
Sourcepub fn get<'de, T: Deserialize<'de>>(
&self,
name: impl ToConfigNamePath,
) -> Result<T, ConfigGetError>
pub fn get<'de, T: Deserialize<'de>>( &self, name: impl ToConfigNamePath, ) -> Result<T, ConfigGetError>
Looks up value of the specified type T
from all layers, merges sub
fields as needed.
Sourcepub fn get_value(
&self,
name: impl ToConfigNamePath,
) -> Result<ConfigValue, ConfigGetError>
pub fn get_value( &self, name: impl ToConfigNamePath, ) -> Result<ConfigValue, ConfigGetError>
Looks up value from all layers, merges sub fields as needed.
Sourcepub fn get_value_with<T, E: Into<Box<dyn Error + Send + Sync>>>(
&self,
name: impl ToConfigNamePath,
convert: impl FnOnce(ConfigValue) -> Result<T, E>,
) -> Result<T, ConfigGetError>
pub fn get_value_with<T, E: Into<Box<dyn Error + Send + Sync>>>( &self, name: impl ToConfigNamePath, convert: impl FnOnce(ConfigValue) -> Result<T, E>, ) -> Result<T, ConfigGetError>
Looks up value from all layers, merges sub fields as needed, then converts the value by using the given function.
Sourcepub fn get_table(
&self,
name: impl ToConfigNamePath,
) -> Result<ConfigTable, ConfigGetError>
pub fn get_table( &self, name: impl ToConfigNamePath, ) -> Result<ConfigTable, ConfigGetError>
Looks up sub table from all layers, merges fields as needed.
Use table_keys(prefix)
and get([prefix, key])
instead if table
values have to be converted to non-generic value type.
Sourcepub fn table_keys(
&self,
name: impl ToConfigNamePath,
) -> impl Iterator<Item = &str>
pub fn table_keys( &self, name: impl ToConfigNamePath, ) -> impl Iterator<Item = &str>
Returns iterator over sub table keys in order of layer precedence. Duplicated keys are omitted.
Trait Implementations§
Source§impl Clone for StackedConfig
impl Clone for StackedConfig
Source§fn clone(&self) -> StackedConfig
fn clone(&self) -> StackedConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for StackedConfig
impl RefUnwindSafe for StackedConfig
impl Send for StackedConfig
impl Sync for StackedConfig
impl Unpin for StackedConfig
impl UnwindSafe for StackedConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more