pub struct KvBackend { /* private fields */ }Expand description
In-memory KV backend, namespaced by plugin name. The outer map is keyed by plugin name; the inner map by user-supplied key.
Four optional caps bound how much a caller (plugin or the
/admin/kv endpoint) can store; 0 on any of them means
“unlimited”. new() / Default leave them all at 0 so existing
callers and tests keep the historical unbounded behaviour;
production wires real values via KvBackend::with_limits.
Implementations§
Source§impl KvBackend
impl KvBackend
pub fn new() -> Self
Sourcepub fn with_limits(
max_value_bytes: usize,
max_keys_per_plugin: usize,
max_plugins: usize,
max_total_bytes: usize,
) -> Self
pub fn with_limits( max_value_bytes: usize, max_keys_per_plugin: usize, max_plugins: usize, max_total_bytes: usize, ) -> Self
Construct with explicit caps. 0 on any field = unlimited.
Sourcepub fn max_value_bytes(&self) -> usize
pub fn max_value_bytes(&self) -> usize
The configured single key/value byte cap (0 = unlimited).
Lets a caller (e.g. the /admin/kv PUT handler) fast-reject an
oversized body before allocating an owned copy of it.
Sourcepub fn set(&self, plugin: &str, key: Vec<u8>, value: Vec<u8>) -> bool
pub fn set(&self, plugin: &str, key: Vec<u8>, value: Vec<u8>) -> bool
Insert / overwrite. Returns false (and leaves the store
untouched) when a configured cap would be exceeded:
- the key OR value length exceeds
max_value_bytes, or - creating a NEW plugin namespace would push the store past
max_plugins, or - inserting a NEW key would push the namespace past
max_keys_per_plugin, or - the resulting
total_byteswould exceedmax_total_bytes.
Overwriting an existing key (or writing another key into an already-present namespace) never fails the key-count or namespace cap. Every cap is checked BEFORE any mutation, so a rejected write leaves the store and the byte counter unchanged.
Sourcepub fn delete(&self, plugin: &str, key: &[u8])
pub fn delete(&self, plugin: &str, key: &[u8])
Delete; idempotent. Drops the plugin’s inner map and its
outer-map slot once the namespace becomes empty, so a
delete-heavy caller actually reclaims memory instead of leaving
zombie namespaces behind — this also keeps the max_plugins
namespace count honest (a fully-drained namespace frees a slot).
The reclaimed key/value/namespace bytes are subtracted from the
total_bytes counter so the max_total_bytes cap tracks the
live footprint exactly.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for KvBackend
impl !UnwindSafe for KvBackend
impl Freeze for KvBackend
impl Send for KvBackend
impl Sync for KvBackend
impl Unpin for KvBackend
impl UnsafeUnpin for KvBackend
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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