pub struct ConfigLayer {
pub source: ConfigSource,
pub path: Option<PathBuf>,
pub data: DocumentMut,
}Expand description
Set of configuration variables with source information.
Fields§
§source: ConfigSourceSource type of this layer.
path: Option<PathBuf>Source file path of this layer if any.
data: DocumentMutConfiguration variables.
Implementations§
Source§impl ConfigLayer
impl ConfigLayer
Sourcepub fn empty(source: ConfigSource) -> Self
pub fn empty(source: ConfigSource) -> Self
Creates new layer with empty data.
Sourcepub fn with_data(source: ConfigSource, data: DocumentMut) -> Self
pub fn with_data(source: ConfigSource, data: DocumentMut) -> Self
Creates new layer with the configuration variables data.
Sourcepub fn parse(source: ConfigSource, text: &str) -> Result<Self, ConfigLoadError>
pub fn parse(source: ConfigSource, text: &str) -> Result<Self, ConfigLoadError>
Parses TOML document text into new layer.
Sourcepub fn load_from_file(
source: ConfigSource,
path: PathBuf,
) -> Result<Self, ConfigLoadError>
pub fn load_from_file( source: ConfigSource, path: PathBuf, ) -> Result<Self, ConfigLoadError>
Loads TOML file from the specified path.
Sourcepub fn look_up_table(
&self,
name: impl ToConfigNamePath,
) -> Result<Option<&ConfigTableLike<'_>>, &ConfigItem>
pub fn look_up_table( &self, name: impl ToConfigNamePath, ) -> Result<Option<&ConfigTableLike<'_>>, &ConfigItem>
Looks up sub table by the name path. Returns Some(table) if a table
was found at the path. Returns Err(item) if middle or leaf node wasn’t
a table.
Sourcepub fn look_up_item(
&self,
name: impl ToConfigNamePath,
) -> Result<Option<&ConfigItem>, &ConfigItem>
pub fn look_up_item( &self, name: impl ToConfigNamePath, ) -> Result<Option<&ConfigItem>, &ConfigItem>
Looks up item by the name path. Returns Some(item) if an item
found at the path. Returns Err(item) if middle node wasn’t a table.
Sourcepub fn set_value(
&mut self,
name: impl ToConfigNamePath,
new_value: impl Into<ConfigValue>,
) -> Result<Option<ConfigValue>, ConfigUpdateError>
pub fn set_value( &mut self, name: impl ToConfigNamePath, new_value: impl Into<ConfigValue>, ) -> Result<Option<ConfigValue>, ConfigUpdateError>
Sets new_value to the name path. Returns old value if any.
This function errors out if attempted to overwrite a non-table middle node or a leaf non-inline table. An inline table can be overwritten because it’s syntactically a value.
Sourcepub fn delete_value(
&mut self,
name: impl ToConfigNamePath,
) -> Result<Option<ConfigValue>, ConfigUpdateError>
pub fn delete_value( &mut self, name: impl ToConfigNamePath, ) -> Result<Option<ConfigValue>, ConfigUpdateError>
Deletes value specified by the name path. Returns old value if any.
Returns Ok(None) if middle node wasn’t a table or a value wasn’t
found. Returns Err if attempted to delete a non-inline table. An
inline table can be deleted because it’s syntactically a value.
Sourcepub fn ensure_table(
&mut self,
name: impl ToConfigNamePath,
) -> Result<&mut ConfigTableLike<'_>, ConfigUpdateError>
pub fn ensure_table( &mut self, name: impl ToConfigNamePath, ) -> Result<&mut ConfigTableLike<'_>, ConfigUpdateError>
Inserts tables down to the name path. Returns mutable reference to the
leaf table.
This function errors out if attempted to overwrite a non-table node. In
file-system analogy, this is equivalent to std::fs::create_dir_all().
Trait Implementations§
Source§impl Clone for ConfigLayer
impl Clone for ConfigLayer
Source§fn clone(&self) -> ConfigLayer
fn clone(&self) -> ConfigLayer
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 ConfigLayer
impl RefUnwindSafe for ConfigLayer
impl Send for ConfigLayer
impl Sync for ConfigLayer
impl Unpin for ConfigLayer
impl UnwindSafe for ConfigLayer
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