pub struct Sync { /* private fields */ }Expand description
Ditto’s Sync API, obtained via ditto.sync().
Implementations§
Source§impl Sync
impl Sync
Sourcepub fn subscriptions(&self) -> HashSet<SyncSubscription>
pub fn subscriptions(&self) -> HashSet<SyncSubscription>
Returns a snapshot of handles to all active SyncSubscriptions.
Adding or removing SyncSubscriptions from this set will not cause the
underlying subscriptions to be updated.
§Example
let subscription = ditto.sync().register_subscription("SELECT * FROM cars")?;
let subscriptions = ditto.sync().subscriptions();
assert!(subscriptions.contains(&subscription));Sourcepub fn register_subscription<Q>(
&self,
query: Q,
) -> Result<Arc<SyncSubscription>, DittoError>
pub fn register_subscription<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(query)?;
// Cancel the subscription with `.cancel()`
sync_subscription.cancel();Sourcepub fn start(&self) -> Result<(), DittoError>
pub fn start(&self) -> Result<(), DittoError>
Start syncing on all transports.
By default, Ditto will enable all peer-to-peer transport types.
The network configuration can be customized using Ditto::set_transport_config.
§Example
ditto.sync().start()?;§Errors
Returns an error if the Ditto instance has not been activated with a valid license.
Sourcepub fn stop(&self)
pub fn stop(&self)
Stop syncing on all transports.
You may continue to use the Ditto store locally but no data will sync to or from other devices.
§Example
ditto.sync().stop();Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true if sync is currently active, otherwise returns false.
Use ditto.sync().start() to activate and ditto.sync().stop() to deactivate sync.
§Example
if ditto.sync().is_active() {
println!("Sync is active");
}