Struct Archive

Source
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

Source

pub fn iter_values(&self) -> impl Iterator<Item = (&str, &Value)>

Source

pub fn iter_paths(&self) -> impl Iterator<Item = (&str, &Archive)>

Source

pub fn iter_paths_mut(&mut self) -> impl Iterator<Item = (&str, &mut Archive)>

Source

pub fn iter_values_mut(&mut self) -> impl Iterator<Item = (&str, &mut Value)>

Source

pub fn get_value(&self, key: &str) -> Option<&Value>

Source

pub fn get_value_mut(&mut self, key: &str) -> Option<&mut Value>

Source

pub fn get_path(&self, key: &str) -> Option<&Archive>

Source

pub fn get_path_mut(&mut self, key: &str) -> Option<&mut Archive>

Source

pub fn insert_value(&mut self, key: impl ToCompactString, value: Value)

Source

pub fn insert_path(&mut self, key: impl ToCompactString, value: Archive)

Source

pub fn remove_value(&mut self, key: &str) -> Option<Value>

Source

pub fn remove_path(&mut self, key: &str) -> Option<Archive>

Source

pub fn clear_values(&mut self)

Source

pub fn clear_paths(&mut self)

Source

pub fn is_empty_values(&self) -> bool

Source

pub fn is_empty_paths(&self) -> bool

Source

pub fn len_values(&self) -> usize

Source

pub fn len_paths(&self) -> usize

Source§

impl Archive

Source

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.

Source

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

Source

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.

Source

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.

Source

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

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.

Trait Implementations§

Source§

impl Clone for Archive

Source§

fn clone(&self) -> Archive

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Archive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Archive

Source§

fn default() -> Archive

Returns the “default value” for a type. Read more
Source§

impl<'a> Deserialize<'a> for Archive

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Archive

Source§

fn eq(&self, other: &Archive) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Archive

Source§

fn serialize<S>(&self, se: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Archive

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Entity for T
where T: Send + Sync + Any + Serialize + DeserializeOwned + Clone + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn deserialize(&mut self, de: &mut dyn Deserializer<'_>) -> Result<(), Error>

Source§

fn as_serialize(&self) -> &dyn Serialize

Source§

fn duplicated(&self) -> Arc<dyn Entity>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,