Skip to main content

Persistence

Struct Persistence 

Source
pub struct Persistence { /* private fields */ }

Implementations§

Source§

impl Persistence

Source

pub fn new() -> AppResult<Self>

Creates a new persistence instance for storing key-value data.

This initializes the persistence layer, creating the config directory if needed, and loads existing state from disk if available.

§Returns

Returns an AppResult<Self> containing the new Persistence instance.

§Errors

Returns an error if the config directory cannot be created or accessed.

Source

pub fn get(&self, key: &str) -> Option<&str>

Gets a value from the persistent state.

§Arguments
  • key - The key to look up
§Returns

Returns Some(&str) if the key exists, None otherwise.

Source

pub fn get_or<'a>(&'a self, key: &str, default: &'a str) -> &'a str

Gets a value from the persistent state, or returns the default if not found.

§Arguments
  • key - The key to look up
  • default - The default value to return if key is not found
§Returns

Returns the value if found, otherwise the default.

Source

pub fn delete(&mut self, key: &str) -> bool

Deletes a key from the persistent state.

Marks the state as dirty if the key existed. Call flush() to save to disk.

§Arguments
  • key - The key to delete
§Returns

Returns true if the key existed and was removed, false otherwise.

Source

pub fn is_dirty(&self) -> bool

Returns true if there are unsaved changes.

Source

pub fn len(&self) -> usize

Returns the number of stored key-value pairs.

Source

pub fn is_empty(&self) -> bool

Returns true if no key-value pairs are stored.

Source

pub fn clear(&mut self)

Clears all stored key-value pairs.

Marks the state as dirty. Call flush() to save to disk.

Source

pub fn set(&mut self, key: &str, value: &str) -> AppResult<()>

Sets a value in the persistent state.

Marks the state as dirty. Call flush() to save to disk.

§Arguments
  • key - The key to set
  • value - The value to store
§Returns

Returns Ok(()) on success.

Source

pub fn flush(&mut self) -> AppResult<()>

Forces an immediate save to disk if there are unsaved changes.

§Returns

Returns Ok(()) on success.

§Errors

Returns an error if saving fails.

Trait Implementations§

Source§

impl Clone for Persistence

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Persistence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Persistence

Source§

fn default() -> Persistence

Returns the “default value” for a type. Read more

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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