pub struct Storage(/* private fields */);
Expand description

Provides a high-level, thread-safe interface to the configuration storage system.

Storage acts as the primary access point for users to interact with the underlying storage system. It abstracts away the intricacies of direct storage interactions by wrapping around the inner::Inner type, ensuring concurrent safety.

With Storage, users can seamlessly perform read and write operations on their configuration data without worrying about potential concurrency issues. This design ensures that the storage system remains robust and efficient, even in multi-threaded environments.

Features:

  • Thread Safety: Guarantees safe concurrent access to the configuration storage.
  • High-level Interface: Abstracts the complexities of direct storage interactions, offering a user-friendly API.

Implementations§

source§

impl Storage

source

pub fn storage_id(&self) -> StorageID

Gets ID of this storage instance. ID is unique per single program instance.

source

pub fn find_or_create<'a, T>( &self, path: impl IntoIterator<Item = impl AsRef<str> + 'a> ) -> Result<Group<T>, GroupFindOrCreateError>where T: Template,

Searches for an existing item of type T in the storage, or creates a new one if it doesn’t exist.

Arguments
  • T - The type of item to search for or create.
Returns

A reference to the existing or newly created item of type T. Value remains in template default until you call first update() on it.

source

pub fn find<T: Template>( &self, path: impl Into<PathHash> ) -> Result<Group<T>, GroupFindError>

Find a group with the given path and template type.

Arguments
  • path - The path of the group to find.
Type Parameters
  • T - The type of the template to use for the group.
Returns

Returns a Result containing the found group or a GroupFindError if the group was not found or if the template type does not match the expected type. Value remains in template default until you call first update() on it.

source

pub fn create<'a, T>( &self, path: impl IntoIterator<Item = &'a (impl AsRef<str> + ?Sized + 'a)> ) -> Result<Group<T>, GroupCreationError>where T: Template,

Creates a new instance of the Storage struct with the specified type parameter. Value remains in template default until you call first update() on it.

source

pub fn exporter(&self) -> ExportTask<'_>

Create internal archive export task.

You should explicitly call confirm() to retrieve the exported archive explcitly.

source

pub fn import(&self, archive: Archive) -> ImportOnDrop<'_>

Deserializes the data.

Data Serialization Rules:
  • The root component is the first path component and is written as-is.
  • Subsequent path components must be prefixed with a ~ (tilde) character.
    • If not prefixed, they are treated as a field element of the enclosing path component.
  • A key prefixed with ‘~’ within an existing field is … (Note: The comment here seems to be incomplete; please provide further details.)
Example JSON structure:
{
    "root_path": {
        "~path_component": {
            "field_name": "value",
            "other_field": {
                "~this_is_not_treated_as_path": 123
            }
        },
        "~another_path_component": {},
        "field_name_of_root_path": "yay"
    },
    "another_root_path": {}
}
Returns

An instance of ImportOnDrop which will handle the import operation.

source

pub fn replace_monitor(&self, handler: Box<impl Monitor>) -> Box<dyn Monitor>

Replaces the current monitor with the provided one.

This function dumps the active list of groups to the new monitor sequentially. If the monitor is not efficiently implemented, this operation can significantly impact the performance of all storage consumers and replicators. Therefore, exercise caution when replacing the monitor on a storage instance that’s under heavy use.

Arguments
  • handler - The new monitor to replace the current one.
Returns

The previous monitor that has been replaced.

source

pub fn unset_monitor(&self)

Unset monitor instance.

source

pub fn notify_editions(&self, items: impl IntoIterator<Item = GroupID>)

Send monitor event to storage driver.

Trait Implementations§

source§

impl Clone for Storage

source§

fn clone(&self) -> Storage

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 Storage

source§

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

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

impl Default for Storage

source§

fn default() -> Storage

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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