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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#![warn(rust_2018_idioms)]
#![allow(clippy::all)]
#![warn(clippy::correctness)]
#![cfg_attr(not(test), warn(clippy::perf))]
#![cfg_attr(
    doc,
    warn(
        rustdoc::bare_urls,
        rustdoc::broken_intra_doc_links,
        rustdoc::invalid_codeblock_attributes,
        rustdoc::invalid_rust_codeblocks,
    )
)]
//! # 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`](crate::ditto::builder::DittoBuilder) :
//! ```rust,no_run
//! # use std::sync::Arc;
//! use dittolive_ditto::prelude::*;
//! // 👇 See <https://docs.ditto.live/onboarding> for instructions on obtaining your app ID and
//! //    playground token.
//! let app_id = AppId::from_env("YOUR_APP_ID_VAR").unwrap();
//! let shared_token = "YOUR-PLAYGROUND-TOKEN-HERE".to_string();
//! let cloud_sync = true;
//! let custom_auth_url = None;
//! 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::OnlinePlayground::new(
//!             ditto_root,
//!             app_id,
//!             shared_token,
//!             cloud_sync,
//!             custom_auth_url,
//!         )
//!     })
//!     .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

#[allow(unused_imports)]
#[macro_use]
extern crate ext_trait;
#[allow(unused_extern_crates)]
extern crate ffi_sdk;

#[macro_use]
#[doc(hidden)]
/// Internal utility functions / macros
pub mod utils;

pub mod disk_usage;

/// Provides access to authentication information and methods for logging on to Ditto Cloud.
/// Relevant when using an [`OnlineWithAuthentication`](identity::OnlineWithAuthentication)
/// identity.
pub mod auth;

pub mod ditto;

pub mod error;

pub mod identity;

pub mod fs;

pub mod prelude;

pub mod observer;

pub mod small_peer_info;

pub mod store;

pub mod subscription;

pub mod sync;

pub mod transport;

pub mod types;

#[cfg(test)]
pub(crate) mod test_helpers;