pub struct Setting<T> {
repository: Arc<dyn Repository<SettingItem>>,
key: Key<T>,
}Expand description
A handle to a single setting value in storage.
This type provides async methods to get, update, and delete the setting value.
Obtained via StateClient::setting().
§Example
ⓘ
use bitwarden_state::register_setting_key;
register_setting_key!(const THEME: String = "theme");
let setting = client.platform().state().setting(THEME)?;
// Get the current value
let value: Option<String> = setting.get().await?;
// Update the value
setting.update("dark".to_string()).await?;
// Delete the value
setting.delete().await?;Fields§
§repository: Arc<dyn Repository<SettingItem>>§key: Key<T>Implementations§
Source§impl<T> Setting<T>
impl<T> Setting<T>
Sourcepub fn new(repository: Arc<dyn Repository<SettingItem>>, key: Key<T>) -> Self
pub fn new(repository: Arc<dyn Repository<SettingItem>>, key: Key<T>) -> Self
Create a new setting handle from a repository and key.
Sourcepub async fn get(&self) -> Result<Option<T>, SettingsError>where
T: for<'de> Deserialize<'de>,
pub async fn get(&self) -> Result<Option<T>, SettingsError>where
T: for<'de> Deserialize<'de>,
Get the current value of this setting.
Returns None if the setting doesn’t exist in storage.
§Errors
Returns an error if deserialization fails, which may indicate:
- Schema evolution problems (type definition changed)
- Data corruption
- Type mismatch (wrong
Key<T>type for stored data)
Sourcepub async fn update(&self, value: T) -> Result<(), SettingsError>where
T: Serialize,
pub async fn update(&self, value: T) -> Result<(), SettingsError>where
T: Serialize,
Update (or create) this setting with a new value.
Sourcepub async fn delete(&self) -> Result<(), SettingsError>
pub async fn delete(&self) -> Result<(), SettingsError>
Delete this setting from storage.
Auto Trait Implementations§
impl<T> Freeze for Setting<T>
impl<T> !RefUnwindSafe for Setting<T>
impl<T> Send for Setting<T>where
T: Send,
impl<T> Sync for Setting<T>where
T: Sync,
impl<T> Unpin for Setting<T>where
T: Unpin,
impl<T> !UnwindSafe for Setting<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
Mutably borrows from an owned value. Read more
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
Create a new handle for an Arc value Read more
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
Clone a handle Read more
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<> Read more