Skip to main content

Store

Struct Store 

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

A mod’s store of a scope: values of any Schema type by key, kept in memory and written when it’s flushed. Handles to one store share it.

Implementations§

Source§

impl Store

Source

pub fn open(root: &Path, mod_id: &str, scope: Scope<'_>) -> Store

mod_id’s store of scope under root (the game’s folder or the world’s).

Source

pub fn session(mod_id: &str) -> Store

mod_id’s session store: kept while the game runs, never written.

Source

pub fn get<T>(&self, key: &str) -> Option<T>
where T: Schema,

The value at key, if there’s one of type T.

Source

pub fn get_or_default<T>(&self, key: &str) -> T
where T: Schema + Default,

The value at key, or T’s default.

Source

pub fn set<T>(&self, key: &str, value: &T)
where T: Schema,

value at key.

Source

pub fn update<T, R>(&self, key: &str, change: impl FnOnce(&mut T) -> R) -> R
where T: Schema + Default,

The value at key changed by change (its default when there’s none); what change returns.

Source

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

Takes the value at key out; whether there was one.

Source

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

Source

pub fn keys(&self) -> Vec<String>

Every key, in the order they were first set.

Source

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

Writes it now if it changed (else it’s written with every store, see crate::flush_all).

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

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

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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

Source§

fn arg(self) -> T

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