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
impl Storage
sourcepub fn storage_id(&self) -> StorageID
pub fn storage_id(&self) -> StorageID
Gets ID of this storage instance. ID is unique per single program instance.
sourcepub fn find_or_create<'a, T>(
&self,
path: impl IntoIterator<Item = impl AsRef<str> + 'a>
) -> Result<Group<T>, GroupFindOrCreateError>where
T: Template,
pub fn find_or_create<'a, T>( &self, path: impl IntoIterator<Item = impl AsRef<str> + 'a> ) -> Result<Group<T>, GroupFindOrCreateError>where T: Template,
sourcepub fn find<T: Template>(
&self,
path: impl Into<PathHash>
) -> Result<Group<T>, GroupFindError>
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.
sourcepub fn create<'a, T>(
&self,
path: impl IntoIterator<Item = &'a (impl AsRef<str> + ?Sized + 'a)>
) -> Result<Group<T>, GroupCreationError>where
T: Template,
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.
sourcepub fn exporter(&self) -> ExportTask<'_>
pub fn exporter(&self) -> ExportTask<'_>
Create internal archive export task.
You should explicitly call confirm() to retrieve the exported archive explcitly.
sourcepub fn import(&self, archive: Archive) -> ImportOnDrop<'_>
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.
sourcepub fn replace_monitor(&self, handler: Box<impl Monitor>) -> Box<dyn Monitor>
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.
sourcepub fn unset_monitor(&self)
pub fn unset_monitor(&self)
Unset monitor instance.
sourcepub fn notify_editions(&self, items: impl IntoIterator<Item = GroupID>)
pub fn notify_editions(&self, items: impl IntoIterator<Item = GroupID>)
Send monitor event to storage driver.