1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! # 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 std::sync::Arc;
//! 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`](crate::store::collection::Collection) in the
//! [`Store`](crate::store::Store).
//! ```
//! # use dittolive_ditto::prelude::Ditto;
//! # fn doc_store(ditto:Ditto) {
//! let store = ditto.store();
//! let collection = store.collection("fancy_name");
//! # }
//! ```
//! And finally add some content inside, which we name
//! [`Document`](crate::store::collection::document).
//! ```
//! # use dittolive_ditto::prelude::Ditto;
//! # use dittolive_ditto::store::collection::Collection;
//! # fn test_collection(collection: Collection) {
//! 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);
//! # }
//! ```
// TODO(Ronan) Expand Doc with more advanced use cases
extern crate ext_trait;
extern crate ffi_sdk;
/// Internal utility functions / macros
/// Provides access to authentication information and methods for logging on to Ditto Cloud.
/// Relevant when using an [`OnlineWithAuthentication`](identity::OnlineWithAuthentication)
/// identity.
pub