pub struct StorageKey(/* private fields */);Expand description
A hierarchical key for storage operations in the samod-core system.
StorageKey represents a path-like key structure that supports efficient
prefix-based operations. Keys are composed of string components that form
a hierarchy, similar to filesystem paths or namespaces.
§Usage
Storage keys are used throughout samod-core for organizing data in the key-value store. They support operations like prefix matching for range queries and hierarchical organization of related data.
§Examples
use samod_core::StorageKey;
// Create keys from string vectors
let key1 = StorageKey::from_parts(vec!["users", "123", "profile"]).unwrap();
let key2 = StorageKey::from_parts(vec!["users", "123", "settings"]).unwrap();
let prefix = StorageKey::from_parts(vec!["users", "123"]).unwrap();
// Check prefix relationships
assert!(prefix.is_prefix_of(&key1));
assert!(prefix.is_prefix_of(&key2));Implementations§
Source§impl StorageKey
impl StorageKey
pub fn storage_id_path() -> StorageKey
pub fn incremental_prefix(doc_id: &DocumentId) -> StorageKey
pub fn incremental_path( doc_id: &DocumentId, change_hash: ChangeHash, ) -> StorageKey
pub fn snapshot_prefix(doc_id: &DocumentId) -> StorageKey
pub fn snapshot_path( doc_id: &DocumentId, compaction_hash: &CompactionHash, ) -> StorageKey
Sourcepub fn from_parts<I: IntoIterator<Item = S>, S: AsRef<str>>(
parts: I,
) -> Result<Self, InvalidStorageKey>
pub fn from_parts<I: IntoIterator<Item = S>, S: AsRef<str>>( parts: I, ) -> Result<Self, InvalidStorageKey>
Sourcepub fn is_prefix_of(&self, other: &StorageKey) -> bool
pub fn is_prefix_of(&self, other: &StorageKey) -> bool
Sourcepub fn onelevel_deeper(&self, prefix: &StorageKey) -> Option<StorageKey>
pub fn onelevel_deeper(&self, prefix: &StorageKey) -> Option<StorageKey>
Checks if this key is one level deeper then the given prefix
§Examples
let key = StorageKey::from_parts(vec!["a", "b", "c"]).unwrap();
let prefix = StorageKey::from_parts(vec!["a", "b"]).unwrap();
assert_eq!(key.onelevel_deeper(&prefix), Some(StorageKey::from_parts(vec!["a", "b", "c"]).unwrap()));
let prefix2 = StorageKey::from_parts(vec!["a"]).unwrap();
assert_eq!(key.onelevel_deeper(&prefix2), Some(StorageKey::from_parts(vec!["a", "b"]).unwrap()));
let prefix3 = StorageKey::from_parts(vec!["a", "b", "c", "d"]).unwrap();
assert_eq!(key.onelevel_deeper(&prefix3), None);pub fn with_suffix(&self, suffix: StorageKey) -> StorageKey
Sourcepub fn with_component(
&self,
component: String,
) -> Result<StorageKey, InvalidStorageKey>
pub fn with_component( &self, component: String, ) -> Result<StorageKey, InvalidStorageKey>
Create a new StorageKey with the given component appended.
§Errors
Returns an error if the new component is empty or contains a forward slash.
Trait Implementations§
Source§impl Clone for StorageKey
impl Clone for StorageKey
Source§fn clone(&self) -> StorageKey
fn clone(&self) -> StorageKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StorageKey
impl Debug for StorageKey
Source§impl Display for StorageKey
impl Display for StorageKey
Source§impl Hash for StorageKey
impl Hash for StorageKey
Source§impl<'a> IntoIterator for &'a StorageKey
impl<'a> IntoIterator for &'a StorageKey
Source§impl IntoIterator for StorageKey
impl IntoIterator for StorageKey
Source§impl PartialEq for StorageKey
impl PartialEq for StorageKey
impl Eq for StorageKey
impl StructuralPartialEq for StorageKey
Auto Trait Implementations§
impl Freeze for StorageKey
impl RefUnwindSafe for StorageKey
impl Send for StorageKey
impl Sync for StorageKey
impl Unpin for StorageKey
impl UnwindSafe for StorageKey
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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