Crate dittolive_ditto
source · [−]Expand description
What is Ditto
?
Ditto
is a cross-platform peer-to-peer database that allows apps
to sync with and even without internet connectivity.
Install Ditto into your application, then use the APIs to read and write data into its storage system, and it will then automatically sync any changes to other devices.
Unlike other synchronization solutions, Ditto
is designed for “peer-to-peer” synchronization
where it can directly communicate with other devices even without an Internet connection.
In addition, Ditto
automatically manages the complexity of using multiple network transports,
like Bluetooth, P2P Wi-Fi, and Local Area Network,
to find and connect to other devices and then synchronize any changes.
How to Ditto
First, you need to create a Ditto instance using the DittoBuilder
:
use dittolive_ditto::prelude::*;
let ditto = Ditto::builder()
.with_root(Arc::new(
// 👇 folder where Ditto will keep its persistent data
PersistentRoot::from_current_exe().expect("Invalid Ditto Root"),
))
// 👇 this Identity is used to start developing features using Ditto
.with_identity(|ditto_root| identity::OfflinePlayground::new(ditto_root, AppId::generate()))
.unwrap()
.build()
.unwrap();
Then, create a Collection
in the
Store
.
let store = ditto.store();
let collection = store.collection("fancy_name");
And finally add some content inside, which we name
Document
.
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Car {
color: String,
price: u32,
}
let ford = Car {
color: String::from("black"),
price: 42_000,
};
// 👇 This is the `DocumentId` which will allow you to edit the Document later
let ford_id = collection.upsert(ford);
Modules
OnlineWithAuthentication
identity.Identity
to start syncing with other peers.Peer
s, Collection
s, and
the file system.dittolive
crate.Subscription
s are used to register interest in receiving updates
for specified DittoDocument
s.