StoreHandle

Struct StoreHandle 

Source
pub struct StoreHandle<T> { /* private fields */ }
Expand description

StoreHandle acts as a container that holds store data in memory and provides methods to access and modify this data. The StoreHandle does not manage storage directly but facilitates the read and write operations by holding the data and its identifier.

Implementations§

Source§

impl<T: Storing> StoreHandle<T>

Source

pub fn new(store_id: &str) -> Self

Creates a new StoreHandle instance with the given store_id.

§Arguments
  • store_id - A string slice that holds the identifier for the store.
§Returns

A new StoreHandle instance with the specified store_id and a default store.

Examples found in repository?
examples/handle/main.rs (line 20)
15fn main() {
16    // Initialize the Storage with the defaults
17    let storage = Storage::new("com.github.mazynoah.storage");
18
19    // Create a handle for managing the store data.
20    let mut handle = StoreHandle::<MyStore>::new("handle");
21
22    // Read existing store from storage
23    storage
24        .read(&mut handle)
25        .expect("Failed to read from storage");
26
27    // Modify the store data
28    let counter = handle.get_store_mut();
29
30    counter.increment_count();
31    counter.increment_count();
32    counter.increment_count();
33
34    // Write changes to disk
35    storage
36        .write(&mut handle)
37        .expect("Failed to write to storage");
38
39    let counter = handle.get_store();
40
41    println!("Count: {}", counter.count);
42}
Source

pub fn get_store_mut(&mut self) -> &mut T

Returns a mutable reference to the stored data.

§Returns

A mutable reference to the stored data.

Examples found in repository?
examples/handle/main.rs (line 28)
15fn main() {
16    // Initialize the Storage with the defaults
17    let storage = Storage::new("com.github.mazynoah.storage");
18
19    // Create a handle for managing the store data.
20    let mut handle = StoreHandle::<MyStore>::new("handle");
21
22    // Read existing store from storage
23    storage
24        .read(&mut handle)
25        .expect("Failed to read from storage");
26
27    // Modify the store data
28    let counter = handle.get_store_mut();
29
30    counter.increment_count();
31    counter.increment_count();
32    counter.increment_count();
33
34    // Write changes to disk
35    storage
36        .write(&mut handle)
37        .expect("Failed to write to storage");
38
39    let counter = handle.get_store();
40
41    println!("Count: {}", counter.count);
42}
Source

pub fn get_store(&self) -> &T

Returns a reference to the stored data.

§Returns

A reference to the stored data.

Examples found in repository?
examples/handle/main.rs (line 39)
15fn main() {
16    // Initialize the Storage with the defaults
17    let storage = Storage::new("com.github.mazynoah.storage");
18
19    // Create a handle for managing the store data.
20    let mut handle = StoreHandle::<MyStore>::new("handle");
21
22    // Read existing store from storage
23    storage
24        .read(&mut handle)
25        .expect("Failed to read from storage");
26
27    // Modify the store data
28    let counter = handle.get_store_mut();
29
30    counter.increment_count();
31    counter.increment_count();
32    counter.increment_count();
33
34    // Write changes to disk
35    storage
36        .write(&mut handle)
37        .expect("Failed to write to storage");
38
39    let counter = handle.get_store();
40
41    println!("Count: {}", counter.count);
42}
Source

pub fn store_id(&self) -> &str

Returns a reference to the store identifier.

§Returns

A reference to the store identifier.

Trait Implementations§

Source§

impl<T: Clone> Clone for StoreHandle<T>

Source§

fn clone(&self) -> StoreHandle<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for StoreHandle<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for StoreHandle<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for StoreHandle<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for StoreHandle<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for StoreHandle<T>
where T: RefUnwindSafe,

§

impl<T> Send for StoreHandle<T>
where T: Send,

§

impl<T> Sync for StoreHandle<T>
where T: Sync,

§

impl<T> Unpin for StoreHandle<T>
where T: Unpin,

§

impl<T> UnwindSafe for StoreHandle<T>
where T: UnwindSafe,

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,