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>
impl<T: Storing> StoreHandle<T>
Sourcepub fn new(store_id: &str) -> Self
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}Sourcepub fn get_store_mut(&mut self) -> &mut T
pub fn get_store_mut(&mut self) -> &mut T
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}Sourcepub fn get_store(&self) -> &T
pub fn get_store(&self) -> &T
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}Trait Implementations§
Source§impl<T: Clone> Clone for StoreHandle<T>
impl<T: Clone> Clone for StoreHandle<T>
Source§fn clone(&self) -> StoreHandle<T>
fn clone(&self) -> StoreHandle<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for StoreHandle<T>
impl<T: Debug> Debug for StoreHandle<T>
Source§impl<'de, T> Deserialize<'de> for StoreHandle<T>where
T: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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> 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