pub struct Pref<T>where
T: PrefValue,{ /* private fields */ }Expand description
A typed, persisted, reactive setting (docs/settings.md), declared once as a static:
pub static SNAP: Pref<bool> = Pref::new("sketch.snap", || true);The signal behind it is created on the UI thread on first use, seeded from the store (or
the default when the key is absent or unparsable), and lives for the process. Pref is
Copy, so a row or a closure takes it by value.
Implementations§
Source§impl<T> Pref<T>where
T: PrefValue,
impl<T> Pref<T>where
T: PrefValue,
Sourcepub const fn new(key: &'static str, default: fn() -> T) -> Pref<T>
pub const fn new(key: &'static str, default: fn() -> T) -> Pref<T>
Declare a pref under key with a default. default is a function so the static holds
no value that needs Sync (|| String::new(), || Unit::Celsius).
Sourcepub const fn env(self, var: &'static str) -> Pref<T>
pub const fn env(self, var: &'static str) -> Pref<T>
The env-wins rule: while var is set in the process environment the stored value is
ignored for this run (the signal seeds from the default), so a day launch --env run
and every CI variant loop stay deterministic whatever an earlier run persisted. Writes
still persist.
Sourcepub fn env_forced(&self) -> bool
pub fn env_forced(&self) -> bool
Whether the env-wins variable is set for this run.
Sourcepub fn signal(&self) -> Signal<T>
pub fn signal(&self) -> Signal<T>
The signal behind the pref: hand it to a control or a binding. Created and seeded on first call.
Sourcepub fn get_untracked(&self) -> T
pub fn get_untracked(&self) -> T
Untracked read.
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Write: the signal, which persists (see Self::signal). An unchanged value is a no-op.
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Whether the current value equals the default.
Trait Implementations§
impl<T> Copy for Pref<T>where
T: PrefValue,
Auto Trait Implementations§
impl<T> Freeze for Pref<T>
impl<T> RefUnwindSafe for Pref<T>
impl<T> Send for Pref<T>
impl<T> Sync for Pref<T>
impl<T> Unpin for Pref<T>
impl<T> UnsafeUnpin for Pref<T>
impl<T> UnwindSafe for Pref<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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