pub struct LocalFirstCollection<T, Tr>where
T: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de> + Mergeable + Default,
Tr: SyncTransport + Clone + 'static,{ /* private fields */ }
Expand description
Local-first collection that can synchronize with remote peers
Implementations§
Source§impl<T, Tr> LocalFirstCollection<T, Tr>where
T: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de> + Mergeable + Default,
Tr: SyncTransport + Clone + 'static,
impl<T, Tr> LocalFirstCollection<T, Tr>where
T: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de> + Mergeable + Default,
Tr: SyncTransport + Clone + 'static,
Sourcepub fn with_replica_id(
storage: Storage,
transport: Tr,
replica_id: ReplicaId,
) -> Self
pub fn with_replica_id( storage: Storage, transport: Tr, replica_id: ReplicaId, ) -> Self
Create a collection with a specific replica ID
Sourcepub fn replica_id(&self) -> ReplicaId
pub fn replica_id(&self) -> ReplicaId
Get the replica ID for this collection
Sourcepub async fn insert(&self, key: &str, value: &T) -> Result<(), CollectionError>
pub async fn insert(&self, key: &str, value: &T) -> Result<(), CollectionError>
Insert or update an item
Sourcepub async fn values(&self) -> Result<Vec<T>, CollectionError>
pub async fn values(&self) -> Result<Vec<T>, CollectionError>
Get all values
Sourcepub async fn contains_key(&self, key: &str) -> Result<bool, CollectionError>
pub async fn contains_key(&self, key: &str) -> Result<bool, CollectionError>
Check if a key exists
Sourcepub async fn len(&self) -> Result<usize, CollectionError>
pub async fn len(&self) -> Result<usize, CollectionError>
Get the number of items
Sourcepub async fn is_empty(&self) -> Result<bool, CollectionError>
pub async fn is_empty(&self) -> Result<bool, CollectionError>
Check if the collection is empty
Sourcepub async fn start_sync(&self) -> Result<(), CollectionError>
pub async fn start_sync(&self) -> Result<(), CollectionError>
Start synchronization
Sourcepub async fn stop_sync(&self) -> Result<(), CollectionError>
pub async fn stop_sync(&self) -> Result<(), CollectionError>
Stop synchronization
Sourcepub async fn sync_state(&self) -> Result<SyncState, CollectionError>
pub async fn sync_state(&self) -> Result<SyncState, CollectionError>
Get synchronization state
Sourcepub async fn is_online(&self) -> Result<bool, CollectionError>
pub async fn is_online(&self) -> Result<bool, CollectionError>
Check if online
Sourcepub async fn peer_count(&self) -> Result<usize, CollectionError>
pub async fn peer_count(&self) -> Result<usize, CollectionError>
Get peer count
Sourcepub fn set_auto_sync(&mut self, enabled: bool)
pub fn set_auto_sync(&mut self, enabled: bool)
Set auto-sync mode
Sourcepub async fn force_sync(&self) -> Result<(), CollectionError>
pub async fn force_sync(&self) -> Result<(), CollectionError>
Force synchronization
Sourcepub async fn insert_batch(
&self,
items: impl IntoIterator<Item = (String, T)>,
) -> Result<(), CollectionError>
pub async fn insert_batch( &self, items: impl IntoIterator<Item = (String, T)>, ) -> Result<(), CollectionError>
Insert or update multiple items in a batch
Sourcepub async fn update_batch(
&self,
updates: impl IntoIterator<Item = (String, T)>,
) -> Result<(), CollectionError>
pub async fn update_batch( &self, updates: impl IntoIterator<Item = (String, T)>, ) -> Result<(), CollectionError>
Update multiple items in a batch
Sourcepub async fn remove_batch(
&self,
keys: impl IntoIterator<Item = String>,
) -> Result<(), CollectionError>
pub async fn remove_batch( &self, keys: impl IntoIterator<Item = String>, ) -> Result<(), CollectionError>
Remove multiple items in a batch
Sourcepub async fn get_batch(
&self,
keys: impl IntoIterator<Item = String>,
) -> Result<Vec<(String, Option<T>)>, CollectionError>
pub async fn get_batch( &self, keys: impl IntoIterator<Item = String>, ) -> Result<Vec<(String, Option<T>)>, CollectionError>
Get multiple items by keys
Sourcepub async fn contains_keys(
&self,
keys: impl IntoIterator<Item = String>,
) -> Result<Vec<(String, bool)>, CollectionError>
pub async fn contains_keys( &self, keys: impl IntoIterator<Item = String>, ) -> Result<Vec<(String, bool)>, CollectionError>
Check if multiple keys exist
Sourcepub async fn peers(
&self,
) -> Result<impl Iterator<Item = (ReplicaId, PeerInfo)>, CollectionError>
pub async fn peers( &self, ) -> Result<impl Iterator<Item = (ReplicaId, PeerInfo)>, CollectionError>
Get all peers
Sourcepub async fn sync_info(&self) -> Result<SyncInfo, CollectionError>
pub async fn sync_info(&self) -> Result<SyncInfo, CollectionError>
Get sync information
Auto Trait Implementations§
impl<T, Tr> Freeze for LocalFirstCollection<T, Tr>
impl<T, Tr> !RefUnwindSafe for LocalFirstCollection<T, Tr>
impl<T, Tr> Send for LocalFirstCollection<T, Tr>
impl<T, Tr> Sync for LocalFirstCollection<T, Tr>
impl<T, Tr> Unpin for LocalFirstCollection<T, Tr>where
T: Unpin,
impl<T, Tr> !UnwindSafe for LocalFirstCollection<T, Tr>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SerializableKey for T
impl<T> SerializableKey for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.