Skip to main content

KvBackend

Struct KvBackend 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn get(&self, plugin: &str, key: &[u8]) -> Option<Vec<u8>>

Read a value. None if missing.

Source

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_bytes would exceed max_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.

Source

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.

Source

pub fn len(&self, plugin: &str) -> usize

Returns the number of keys in the plugin’s namespace. Useful for tests and the admin endpoint.

Source

pub fn list_keys(&self, plugin: &str, prefix: &[u8]) -> Vec<String>

List keys (lossy UTF-8) in a plugin’s namespace, optionally filtered by a byte prefix (pass b"" for all keys). Backs the GET /admin/kv/<plugin>/ list endpoint.

Trait Implementations§

Source§

impl Clone for KvBackend

Source§

fn clone(&self) -> KvBackend

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 Default for KvBackend

Source§

fn default() -> KvBackend

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more