Struct rusty_store::StoreHandle
source · pub struct StoreHandle<T> { /* private fields */ }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
Examples found in repository?
examples/manager_trait/main.rs (line 30)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let handle = StoreHandle::<MyStore>::new("manager_trait");
// Use `StorageManager` to manage the store.
let mut manager =
StorageManager::new(&storage, handle).expect("Failed to create StorageManager");
// Modify and save the data using `StorageManager`.
manager
.increment_count()
.expect("Failed to increment count");
let counter = manager.get_store();
println!("Count: {}", counter.count);
}More examples
examples/manager/main.rs (line 20)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let handle = StoreHandle::<MyStore>::new("manager");
// Use `StorageManager` to manage the handle's change.
let mut manager =
StorageManager::new(&storage, handle).expect("Failed to create StorageManager");
// Get a mutable reference to the store
let counter = manager.get_store_mut();
counter.count = 75;
// Save the data to the storage
manager.save().expect("Failed to save count to storage");
let counter = manager.get_store();
println!("Count: {}", counter.count);
}examples/handle/main.rs (line 26)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let mut handle = StoreHandle::<MyStore>::new("handle");
// Read existing store from storage
storage
.read(&mut handle)
.expect("Failed to read from storage");
// Modify the store data
let counter = handle.get_store_mut();
counter.increment_count();
counter.increment_count();
counter.increment_count();
// Write changes to disk
storage
.write(&mut handle)
.expect("Failed to write to storage");
let counter = handle.get_store();
println!("Count: {}", counter.count);
}examples/manager_uncommitted/main.rs (line 30)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let handle = StoreHandle::<MyStore>::new("manager_uncommitted");
// Use `StorageManager` to manage the handle's change.
let mut manager =
StorageManager::new(&storage, handle).expect("Failed to create StorageManager");
// Modify the data without saving the changes to disk.
manager.increment_count();
manager.increment_count();
manager.increment_count();
// Save the data to the storage
manager.save().expect("Failed to save count to storage");
let counter = manager.get_store();
println!("Count: {}", counter.count);
}sourcepub fn get_store_mut(&mut self) -> &mut T
pub fn get_store_mut(&mut self) -> &mut T
Returns a mutable reference to the stored data.
Examples found in repository?
examples/handle/main.rs (line 34)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let mut handle = StoreHandle::<MyStore>::new("handle");
// Read existing store from storage
storage
.read(&mut handle)
.expect("Failed to read from storage");
// Modify the store data
let counter = handle.get_store_mut();
counter.increment_count();
counter.increment_count();
counter.increment_count();
// Write changes to disk
storage
.write(&mut handle)
.expect("Failed to write to storage");
let counter = handle.get_store();
println!("Count: {}", counter.count);
}sourcepub fn get_store(&self) -> &T
pub fn get_store(&self) -> &T
Returns a reference to the stored data.
Examples found in repository?
examples/handle/main.rs (line 45)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Initialize the Storage with the defaults
let storage = Storage::new("com.github.mazynoah.storage".to_owned());
// Create a handle for managing the store data.
let mut handle = StoreHandle::<MyStore>::new("handle");
// Read existing store from storage
storage
.read(&mut handle)
.expect("Failed to read from storage");
// Modify the store data
let counter = handle.get_store_mut();
counter.increment_count();
counter.increment_count();
counter.increment_count();
// Write changes to disk
storage
.write(&mut handle)
.expect("Failed to write to storage");
let counter = handle.get_store();
println!("Count: {}", counter.count);
}pub fn store_id(&self) -> &str
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 copy 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)