pub struct SyncedStore<T> { /* private fields */ }Expand description
A synchronized key-value store with device-owned slices.
Each device owns one slice of type T. Writes update only the local
slice and broadcast the change. Remote slices are received and cached
automatically.
Created via SyncedStore::new or Node::synced_store.
Implementations§
Source§impl<T: Serialize + DeserializeOwned + Clone + Send + Sync + 'static> SyncedStore<T>
impl<T: Serialize + DeserializeOwned + Clone + Send + Sync + 'static> SyncedStore<T>
Sourcepub fn new<N: NetworkProvider + 'static>(
node: Arc<Node<N>>,
store_id: &str,
) -> Arc<Self>
pub fn new<N: NetworkProvider + 'static>( node: Arc<Node<N>>, store_id: &str, ) -> Arc<Self>
Create a new SyncedStore and start the background sync task.
The store syncs on namespace "ss:{store_id}". The caller must hold
an Arc<Node<N>> because the background task needs to outlive this
constructor call.
Sourcepub async fn local(&self) -> Option<T>
pub async fn local(&self) -> Option<T>
This device’s current data, or None if set() hasn’t been called.
Sourcepub async fn get(&self, device_id: &str) -> Option<Slice<T>>
pub async fn get(&self, device_id: &str) -> Option<Slice<T>>
A specific peer’s slice, or None if we haven’t received their data.
Sourcepub async fn device_ids(&self) -> Vec<String>
pub async fn device_ids(&self) -> Vec<String>
Device IDs that have data in this store (local + remote).
Sourcepub fn subscribe(&self) -> Receiver<StoreEvent<T>>
pub fn subscribe(&self) -> Receiver<StoreEvent<T>>
Subscribe to store change events.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for SyncedStore<T>
impl<T> !RefUnwindSafe for SyncedStore<T>
impl<T> Send for SyncedStore<T>
impl<T> Sync for SyncedStore<T>
impl<T> Unpin for SyncedStore<T>
impl<T> UnsafeUnpin for SyncedStore<T>
impl<T> !UnwindSafe for SyncedStore<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