pub struct Sync { /* private fields */ }Expand description
Ditto’s Sync API, obtained via ditto.sync().
Implementations§
Source§impl Sync
impl Sync
Sourcepub fn start(&self) -> Result<(), DittoError>
pub fn start(&self) -> Result<(), DittoError>
Starts the network transports. Ditto will connect to other devices.
By default, Ditto will enable all peer-to-peer transport types.
The network configuration can be customized using
ditto.set_transport_config().
Sourcepub fn stop(&self)
pub fn stop(&self)
Stops syncing on all transports.
You may continue to use the Ditto store locally but no data will sync to or from other devices.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true if sync is currently active, otherwise returns false.
Sourcepub fn subscriptions_v2(&self) -> HashSet<SyncSubscription>
pub fn subscriptions_v2(&self) -> HashSet<SyncSubscription>
Returns a snapshot of handles to all active SyncSubscriptions.
Adding or removing SyncSubscriptions from this map will not cause the
underlying subscriptions to be updated.
§Example
let subscription = ditto
.sync()
.register_subscription("SELECT * FROM cars", None)?;
let subscriptions = ditto.sync().subscriptions_v2();
assert!(subscriptions.contains(&subscription));Sourcepub fn register_subscription_v2<Q>(
&self,
query: Q,
) -> Result<Arc<SyncSubscription>, DittoError>
pub fn register_subscription_v2<Q>( &self, query: Q, ) -> Result<Arc<SyncSubscription>, DittoError>
Use a DQL query to subscribe to data on other Ditto peers.
While the subscription is active, data matching this query on other peers will be synced to the local peer’s data store.
Note that dropping the SyncSubscription won’t cancel it, to do that
be sure to use sync_subscription.cancel().
§Example
use dittolive_ditto::prelude::*;
let query = (
"SELECT * FROM cars WHERE color = :color",
serde_json::json!({"color": "blue"}),
);
let sync_subscription = ditto.sync().register_subscription_v2(query)?;
// Cancel the subscription with `.cancel()`
sync_subscription.cancel();