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
impl SettingsStore
Sourcepub fn poll(
&mut self,
ctx: &Context,
current: &UserSettings,
) -> Option<UserSettings>
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.
Sourcepub fn flush(&mut self, current: &UserSettings) -> bool
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.
Sourcepub fn conflict(&self) -> bool
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.
Sourcepub fn resolve_conflict(&mut self, choice: ConflictChoice)
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.
Sourcepub fn take_error(&mut self) -> Option<String>
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§
impl !RefUnwindSafe for SettingsStore
impl !UnwindSafe for SettingsStore
impl Freeze for SettingsStore
impl Send for SettingsStore
impl Sync for SettingsStore
impl Unpin for SettingsStore
impl UnsafeUnpin for SettingsStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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