Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

Typed, scoped persistent key-value store.

Mutations are buffered in memory. The store is auto-flushed on Drop if any key was mutated. Call flush explicitly when you need the data on disk immediately (e.g. end of a critical event handler).

Implementations§

Source§

impl Storage

Source

pub fn open(game_dir: &str, mod_id: &str) -> Storage

Open the global store for mod_id.

Source

pub fn open_scoped( game_dir: &str, mod_id: &str, scope: StorageScope<'_>, ) -> Storage

Open a store with an explicit StorageScope.

Source

pub fn open_player(game_dir: &str, mod_id: &str, player_uuid: &str) -> Storage

Open a per-player store (keyed by player UUID).

Source

pub fn open_world(game_dir: &str, mod_id: &str, dimension: &str) -> Storage

Open a per-dimension store.

Source

pub fn open_entity(game_dir: &str, mod_id: &str, entity_uuid: &str) -> Storage

Open a per-entity store (keyed by entity UUID).

Source

pub fn open_chunk( game_dir: &str, mod_id: &str, dimension: &str, cx: i32, cz: i32, ) -> Storage

Open a per-chunk store.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Source

pub fn get_str(&self, key: &str) -> Option<&str>

Source

pub fn get_int(&self, key: &str) -> Option<i64>

Source

pub fn get_float(&self, key: &str) -> Option<f64>

Source

pub fn get_bool(&self, key: &str) -> Option<bool>

Source

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

Source

pub fn contains(&self, key: &str) -> bool

Source

pub fn set(&mut self, key: impl Into<String>, value: impl Into<Value>)

Insert or replace a value.

Accepts any type that implements Into<Value>i64, f64, bool, &str, String, Vec<u8>, etc.

Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Source

pub fn clear(&mut self)

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_dirty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &Value)>

Source

pub fn path(&self) -> &Path

Absolute path of the backing file.

Source

pub fn flush(&mut self) -> Result<(), Error>

Atomically write all data to disk.

Writes to <path>.kv.tmp first, then renames it over <path>. A crash mid-write leaves the previous on-disk state intact.

Trait Implementations§

Source§

impl Drop for Storage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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, 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.