Struct ark_api::storage::Store

source ·
pub struct Store { /* private fields */ }
Expand description

Simple key-value data store for which all values are loaded at startup.

Prefer using AsyncStore for large data stores.

Implementations§

source§

impl Store

source

pub fn open(realm: StoreRealm, name: StoreName) -> Self

Open a store for a specific realm and name.

If the store doesn’t exist, locally or globally, it will be automatically created.

Names of stores is limited to max 32 characters and can only be alphanumeric or dash or underscore.

Global stores

Note that for StoreRealm::Global this can be a very expensive operation as it will synchronize and download latest data. Prefer to call this early in module initialization.

Also the store name is global, so be precise and unique in your naming to not pollute or collide other stores.

Panics

This function panics if a store could not be opened for the given name.

source

pub fn async_open(realm: StoreRealm, name: StoreName) -> OpenSyncStorePromise

Start opening a store for a specific realm and name.

If the store doesn’t exist, locally or globally, it will be automatically created.

Names of stores is limited to max 32 characters and can only be alphanumeric or dash or underscore.

Global stores

The store name is global, so be precise and unique in your naming to not pollute or collide other stores.

Panics

This function panics if a store could not be opened for the given name.

source

pub fn insert<K: AsRef<[u8]>, V: AsRef<[u8]>>(&mut self, key: K, value: V)

Insert a key

If the key already exists in the store, it will be overwritten

source

pub fn remove<K: AsRef<[u8]>>(&mut self, key: K)

Remove a key

source

pub fn keys(&self) -> Keys

Get a list of all keys currently in the store.

Note that this is a snapshot from the time of the call, for stores using StoreRealm::Global there is a chance keys can be removed while one is iterating through this list, and new keys can also be added or the value of the keys changed

This can be bit expensive operation for stores that contain a lot of keys

source

pub fn contains<K: AsRef<[u8]>>(&self, key: K) -> bool

Check if the store has a specific key

source

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

Get the value of a key, if available

Trait Implementations§

source§

impl Clone for Store

source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for Store

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PartialEq<Store> for Store

source§

fn eq(&self, other: &Store) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Store

Auto Trait Implementations§

§

impl RefUnwindSafe for Store

§

impl !Send for Store

§

impl !Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.