pub struct Archive { /* private fields */ }
Expand description
Represents a hierarchical archive of configuration values and categories.
The Archive
struct organizes configuration data into a tree-like structure. Each node in this
structure can represent either a configuration category (identified by a path) or an individual
configuration value.
Categories within the archive are uniquely identified by keys that are prefixed with a special
character, typically ~
, though this can be customized using with_category_rule
. Each
category can further contain nested categories and values, allowing for a deeply nested
hierarchical organization of configuration data.
Configuration values within a category are stored as key-value pairs, where the key is a string representing the configuration name, and the value is its associated JSON representation.
This structure provides a compact and efficient way to represent, serialize, and deserialize configuration data with support for custom category naming conventions.
Implementations§
Source§impl Archive
impl Archive
pub fn iter_values(&self) -> impl Iterator<Item = (&str, &Value)>
pub fn iter_paths(&self) -> impl Iterator<Item = (&str, &Archive)>
pub fn iter_paths_mut(&mut self) -> impl Iterator<Item = (&str, &mut Archive)>
pub fn iter_values_mut(&mut self) -> impl Iterator<Item = (&str, &mut Value)>
pub fn get_value(&self, key: &str) -> Option<&Value>
pub fn get_value_mut(&mut self, key: &str) -> Option<&mut Value>
pub fn get_path(&self, key: &str) -> Option<&Archive>
pub fn get_path_mut(&mut self, key: &str) -> Option<&mut Archive>
pub fn insert_value(&mut self, key: impl ToCompactString, value: Value)
pub fn insert_path(&mut self, key: impl ToCompactString, value: Archive)
pub fn remove_value(&mut self, key: &str) -> Option<Value>
pub fn remove_path(&mut self, key: &str) -> Option<Archive>
pub fn clear_values(&mut self)
pub fn clear_paths(&mut self)
pub fn is_empty_values(&self) -> bool
pub fn is_empty_paths(&self) -> bool
pub fn len_values(&self) -> usize
pub fn len_paths(&self) -> usize
Source§impl Archive
impl Archive
Sourcepub fn find_path<'s, 'a, T: AsRef<str> + 'a>(
&'s self,
path: impl IntoIterator<Item = T>,
) -> Option<&'s Archive>
pub fn find_path<'s, 'a, T: AsRef<str> + 'a>( &'s self, path: impl IntoIterator<Item = T>, ) -> Option<&'s Archive>
Searches for a nested category within the archive using the specified path.
Given a path (as an iterator of strings), this method traverses the archive hierarchically to locate the target category.
§Parameters
path
: The path of the target category, represented as an iterable of strings.
§Returns
An Option
containing a reference to the found Archive
(category) if it exists,
or None
otherwise.
Sourcepub fn find_or_create_path_mut<'s, 'a>(
&'s mut self,
path: impl IntoIterator<Item = &'a str>,
) -> &'s mut Archive
pub fn find_or_create_path_mut<'s, 'a>( &'s mut self, path: impl IntoIterator<Item = &'a str>, ) -> &'s mut Archive
Retrieves a mutable reference to a nested category, creating it if it doesn’t exist.
This method is useful for ensuring a category exists at a certain path, creating any necessary intermediate categories along the way.
§Parameters
path
: The path of the target category, represented as an iterable of strings.
§Returns
A mutable reference to the target Archive
(category).
Sourcepub fn create_patch(&self, newer: &mut Self) -> Self
pub fn create_patch(&self, newer: &mut Self) -> Self
Generates a differential patch between the current and a newer archive.
This method examines the differences between the current archive and a provided newer
archive. The result is an Archive
containing only the differences. The method also
modifies the newer
archive in place, removing the elements that are part of the patch.
§Parameters
newer
: A mutable reference to the newer version of the archive.
§Returns
An Archive
containing only the differences between the current and newer archives.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the archive is empty.
An archive is considered empty if it has no categories (paths) and no values.
§Returns
true
if the archive is empty, otherwise false
.
Sourcepub fn merge_from(&mut self, other: Self)
pub fn merge_from(&mut self, other: Self)
Merges data from another archive into the current one.
This method recursively merges categories and replaces values from the other archive into the current one. In the case of overlapping categories, it will dive deeper and merge the inner values and categories.
§Parameters
other
: The other archive to merge from.
Sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Merges data from another archive into a clone of the current one and returns the merged result.
This method is a combinatory operation that uses merge_from
under the hood but doesn’t
modify the current archive in place, instead, it returns a new merged archive.
§Parameters
other
: The other archive to merge from.
§Returns
A new Archive
which is the result of merging the current archive with the provided one.