Skip to main content

SettingsStore

Struct SettingsStore 

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

Keeps UserSettings in the host’s Storage: reads them once, then writes them a second after they last changed. A failed write keeps the settings in memory and is reported once by take_error; a later poll or explicit flush retries it. Settings that could not be read are never written over. If the host keeps revisions of documents (see Storage), a change by another client is read once nothing is unsaved and returned like the first read, and a write over a newer version is refused: conflict then asks for the user’s choice and resolve_conflict applies it.

Implementations§

Source§

impl SettingsStore

Source

pub const DELAY: Duration

How long settings stay the same before they are written.

Source

pub fn new(storage: Arc<dyn Storage>) -> Self

Starts reading the settings from storage.

Source

pub fn poll( &mut self, ctx: &Context, current: &UserSettings, ) -> Option<UserSettings>

Call every frame with the settings as they are. Returns the stored settings in the frame they arrive, for the host to apply: once read, and again after a change by another client or a conflict settled by reloading; until the first read nothing is written. Writes current once it has stayed the same for DELAY, and at once while a conflict is unsettled, so that the choice applies to the newest settings.

Source

pub fn flush(&mut self, current: &UserSettings) -> bool

Writes current now if it differs from the stored settings, such as when the application exits, and returns whether storage has acknowledged it. Nothing is written before the settings are read, after they could not be read, while stored settings that poll has not returned yet are pending, nor while a conflict is unsettled; it returns false then, so a host that waits for true bounds the wait.

Source

pub fn conflict(&self) -> bool

Whether the host refused to write the settings because another client changed them, and the user’s choice is awaited. The settings stay in memory and nothing is written until resolve_conflict settles it.

Source

pub fn resolve_conflict(&mut self, choice: ConflictChoice)

Settles a refused write with the user’s choice. Reloading the stored settings returns them from the next poll, like the first read; keeping a local copy saves the unsaved settings as a new document first, named settings (local copy), or settings (local copy 2) and so on if that name is taken.

Source

pub fn take_error(&mut self) -> Option<String>

The error of a failed read or write since the last call, to show to the user.

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
§

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

§

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

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> 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> MaybeSend for T
where T: Send + Sync + ?Sized,

§

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

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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.