pub struct PluginStore { /* private fields */ }Expand description
One plugin’s durable key/value store.
Construct through PluginStore::open; share through a
PluginStoreHandle. Never fails to open: an unreadable, corrupt or
stale file yields an empty store with a debug log.
Implementations§
Source§impl PluginStore
impl PluginStore
Sourcepub fn open(dir: &Path) -> Self
pub fn open(dir: &Path) -> Self
Open (or start) the store held in dir — the plugin’s private data
directory, so two plugins cannot collide and uninstalling one removes
what it persisted.
Never fails. Every unreadable case degrades to an empty store, which the next write repopulates.
Sourcepub fn put(&mut self, key: &str, value: Vec<u8>) -> Result<(), String>
pub fn put(&mut self, key: &str, value: Vec<u8>) -> Result<(), String>
Store value under key, bumping generation.
Err only for a value that cannot fit at all; a value that merely does
not fit alongside what is there clears the store first and is then
stored, because the alternative — refusing the newest write — leaves a
full store permanently unable to record the thing it is being asked to
remember.
Sourcepub fn get(&self, key: &str) -> Option<Vec<u8>>
pub fn get(&self, key: &str) -> Option<Vec<u8>>
The bytes under key, or None when nothing is stored there.
Sourcepub fn delete(&mut self, key: &str) -> Result<(), String>
pub fn delete(&mut self, key: &str) -> Result<(), String>
Forget key. Deleting what is not there is Ok — a retraction that has
already happened is not an error — but it does NOT bump the generation,
because nothing changed and a reader that rebuilt for it would be
rebuilding for nothing.
Sourcepub fn keys(&self, prefix: &str) -> Vec<String>
pub fn keys(&self, prefix: &str) -> Vec<String>
Keys carrying prefix, sorted. "" lists everything.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
The mutation counter a reader compares against what it last built from.
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Write the store out. Best-effort: a failure is logged and dropped, because a store that cannot be written is a store that rebuilds on the next boot — degraded, not wrong.
Written to a temporary file and renamed, so a kill mid-write leaves the previous state intact rather than a truncated file the next boot has to recognise as corrupt.
Trait Implementations§
Source§impl Debug for PluginStore
impl Debug for PluginStore
Source§impl Drop for PluginStore
impl Drop for PluginStore
Auto Trait Implementations§
impl Freeze for PluginStore
impl RefUnwindSafe for PluginStore
impl Send for PluginStore
impl Sync for PluginStore
impl Unpin for PluginStore
impl UnsafeUnpin for PluginStore
impl UnwindSafe for PluginStore
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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> ⓘ
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> ⓘ
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