Preferences

Struct Preferences 

Source
pub struct Preferences<E>
where E: Error + Debug + From<Error> + Send + 'static,
{ /* private fields */ }
Expand description

Preferences collection with a backing storage provider.

Implementations§

Source§

impl<E> Preferences<E>
where E: Error + Debug + From<Error> + Send + 'static,

Source

pub fn new( provider: Arc<PreferenceStorageProvider<E>>, account_id: Option<AccountId>, ) -> Self

Create new preferences using the given storage provider.

Source

pub async fn load(&mut self) -> Result<(), E>

Load the preferences from storage.

Source

pub fn len(&self) -> usize

Number of preferences.

Source

pub fn is_empty(&self) -> bool

Whether the preferences collection is empty.

Source

pub fn values(&self) -> &PreferenceMap

Map of preferences.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &Preference)>

Iterator of the preferences.

Source

pub fn get_number(&self, key: impl AsRef<str>) -> Result<Option<&Preference>, E>

Get a number preference.

Source

pub fn get_bool(&self, key: impl AsRef<str>) -> Result<Option<&Preference>, E>

Get a boolean preference.

Source

pub fn get_string(&self, key: impl AsRef<str>) -> Result<Option<&Preference>, E>

Get a string preference.

Source

pub fn get_string_list( &self, key: impl AsRef<str>, ) -> Result<Option<&Preference>, E>

Get a string list preference.

Source

pub fn get_json_value( &self, key: impl AsRef<str>, ) -> Result<Option<&Preference>, E>

Get a JSON value preference.

Source

pub fn get_unchecked(&self, key: impl AsRef<str>) -> Option<&Preference>

Get a preference without checking the type.

Source

pub async fn insert(&mut self, key: String, value: Preference) -> Result<(), E>

Insert a preference.

If the preference already exists it is overwritten.

Source

pub async fn remove( &mut self, key: impl AsRef<str>, ) -> Result<Option<Preference>, E>

Remove a preference.

Source

pub async fn clear(&mut self) -> Result<(), E>

Clear all preferences.

Auto Trait Implementations§

§

impl<E> Freeze for Preferences<E>

§

impl<E> !RefUnwindSafe for Preferences<E>

§

impl<E> Send for Preferences<E>

§

impl<E> Sync for Preferences<E>

§

impl<E> Unpin for Preferences<E>

§

impl<E> !UnwindSafe for Preferences<E>

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

Source§

type Output = T

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