Skip to main content

ScopedKvStore

Struct ScopedKvStore 

Source
pub struct ScopedKvStore<KV> { /* private fields */ }
Expand description

A directory-pinned view of another KvStore.

The store is pinned to a directory, and every operation’s directory argument is a relative path from the pin: the empty path names the pinned directory itself, and a non-empty path names a subdirectory of it. The inner store sees the joined absolute path; the caller never types the pinned part again. Bounds pass through unchanged — they are always over the within-directory key, so a scan yields keys of the directory the call names.

The pinned directory (and any relative subdirectory) is created lazily like any other (the first write allocates it); reads on a never-written directory are empty.

This type is scope plumbing, not a capability boundary. Self::inner, Self::inner_mut, and Self::into_inner deliberately expose the wrapped store, through which code may access any directory. Callers that need structural isolation must not hand out those escape hatches. Higher layers own that restriction; the scoped handles held by state-machine crates are the actual capability boundary.

§Commit

Commit forwards straight through, unwrapped: pinning a directory cannot fail at commit time, so there is no scoped error to introduce and the caller keeps the backend’s own commit error type.

Implementations§

Source§

impl<KV> ScopedKvStore<KV>

Source

pub fn new(inner: KV, dir: impl Into<Vec<Vec<u8>>>) -> Self

Wrap inner, pinning every operation under the directory dir: a caller path p is issued to the inner store as dir ++ p.

An empty directory pins the root and yields a transparent pass-through view.

Source

pub fn dir(&self) -> &[Vec<u8>]

The pinned directory, as owned segments.

Source

pub fn inner(&self) -> &KV

Borrow the wrapped store, which still sees any directory.

Source

pub fn inner_mut(&mut self) -> &mut KV

Mutably borrow the wrapped store, which still sees any directory.

Source

pub fn into_inner(self) -> KV

Unwrap, returning the underlying store.

Source

pub fn nested(self, seg: impl Into<Vec<u8>>) -> Self

Build a further-nested scope by appending one segment to this directory.

Consumes self, since the outer view and the nested view would otherwise both claim ownership of the same backend.

Trait Implementations§

Source§

impl<KV: Clone> Clone for ScopedKvStore<KV>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<KV: Commit> Commit for ScopedKvStore<KV>

Source§

type Error = <KV as Commit>::Error

Error type produced by the commit itself. Read more
Source§

fn commit(self) -> impl Future<Output = Result<(), Self::Error>>

Finalize every write performed through this handle, atomically. Read more
Source§

impl<KV> Debug for ScopedKvStore<KV>

Source§

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

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

impl<KV: Eq> Eq for ScopedKvStore<KV>

Source§

impl<KV: KvDirNav> KvDirNav for ScopedKvStore<KV>

Source§

async fn list_dirs(&self, dir: &[&[u8]]) -> Result<Vec<Vec<u8>>, Self::Error>

List the immediate child directory names under dir, as segment bytes, sorted ascending. Read more
Source§

async fn dir_exists(&self, dir: &[&[u8]]) -> Result<bool, Self::Error>

Whether the directory exists. Read more
Source§

async fn remove_dir(&mut self, dir: &[&[u8]]) -> Result<bool, Self::Error>

Remove dir recursively: its subdirectories (child rows and data) and all of dir’s own key data. Read more
Source§

impl<KV: KvStore> KvStore for ScopedKvStore<KV>

Source§

type Error = <KV as KvStore>::Error

The error type for this store.
Source§

async fn get( &self, dir: &[&[u8]], key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>

Get a value by directory and key. Read more
Source§

async fn set( &mut self, dir: &[&[u8]], key: &[u8], value: &[u8], ) -> Result<(), Self::Error>

Set a key-value pair in a directory, overwriting any existing value for the key. The directory (and any missing ancestor) is allocated if needed.
Source§

async fn delete(&mut self, dir: &[&[u8]], key: &[u8]) -> Result<(), Self::Error>

Delete a key from a directory. Read more
Source§

async fn exists(&self, dir: &[&[u8]], key: &[u8]) -> Result<bool, Self::Error>

Check whether a key exists in a directory. Read more
Source§

fn range<'a>( &'a self, dir: &[&[u8]], start: Bound<&'a [u8]>, end: Bound<&'a [u8]>, reverse: bool, ) -> KvStream<'a, Self::Error>

Scan the keys of one directory between two key bounds, in lexicographic order. Read more
Source§

async fn clear_range( &mut self, dir: &[&[u8]], start: Bound<&[u8]>, end: Bound<&[u8]>, ) -> Result<(), Self::Error>

Delete every key in a range within one directory. Read more
Source§

impl<KV: PartialEq> PartialEq for ScopedKvStore<KV>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<KV: PartialEq> StructuralPartialEq for ScopedKvStore<KV>

Auto Trait Implementations§

§

impl<KV> Forget for ScopedKvStore<KV>

§

impl<KV> Freeze for ScopedKvStore<KV>
where KV: Freeze, *const u8 is !null: Freeze, PhantomData<Vec<u8>>: Freeze,

§

impl<KV> Move for ScopedKvStore<KV>

§

impl<KV> RefUnwindSafe for ScopedKvStore<KV>
where KV: RefUnwindSafe,

§

impl<KV> Send for ScopedKvStore<KV>
where KV: Send, RawVecInner: Send,

§

impl<KV> Sync for ScopedKvStore<KV>
where KV: Sync, RawVecInner: Sync,

§

impl<KV> Unpin for ScopedKvStore<KV>
where KV: Unpin, *const u8 is !null: Unpin,

§

impl<KV> UnsafeUnpin for ScopedKvStore<KV>

§

impl<KV> UnwindSafe for ScopedKvStore<KV>
where KV: UnwindSafe, RawVecInner: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.