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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! # Dodo
//!
//! Dodo (pronounced `doe doe`) is a very basic persistence library designed to be a quick and easy
//! way to create a persistent storage. It uses [Serde] under the hood to perform serialization of
//! the persisted data.
//!
//! ## Getting Started
//!
//! First, create a struct implementing the [Entity], [Serialize] and [Deserialize] traits, which
//! can be done using derives. For the `Entity` derive to work, it must contain a field named `id`
//! of type `Option<Uuid>`.
//!
//! ```
//! # use dodo::prelude::*;
//! # use serde::{Deserialize, Serialize};
//! # use uuid::Uuid;
//! #[derive(Entity, Serialize, Deserialize)]
//! #[serde(rename_all = "camelCase")]
//! struct Person {
//!     id: Option<Uuid>,
//!     name: String,
//!     age: u64,
//! }
//! ```
//!
//! Then, create a [storage][Storage] for your data. You can implement your own, or use the
//! default [Directory] storage.
//!
//! ```
//! # use dodo::prelude::*;
//! #
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! #    let tempdir  = tempfile::tempdir()?;
//! #    let path  = tempdir.path();
//! let directory = Directory::new(path)?;
//! #    Ok(())
//! # }
//! ```
//!
//! Now, you must choose a [serializer][Serializer]. You can also implement your own, or
//! use the default [JsonSerializer]. When this is done, it is highly recommanded to create a type
//! definition for your [repository][Repository] using the chosen storage and serializer.
//!
//! ```
//! # use dodo::prelude::*;
//! # use serde::{Deserialize, Serialize};
//! # use uuid::Uuid;
//! #
//! # #[derive(Entity, Serialize, Deserialize)]
//! # #[serde(rename_all = "camelCase")]
//! # struct Person {
//! #     id: Option<Uuid>,
//! #     name: String,
//! #     age: u64,
//! # }
//! #
//! type PersonRepository = Repository<Person, Directory, JsonSerializer>;
//! ```
//!
//! Finally, create a [repository][Repository] and start using it.
//!
//! ```
//! # use dodo::prelude::*;
//! # use serde::{Deserialize, Serialize};
//! # use uuid::Uuid;
//! #
//! # #[derive(Debug, Entity, Serialize, Deserialize)]
//! # #[serde(rename_all = "camelCase")]
//! # struct Person {
//! #     id: Option<Uuid>,
//! #     name: String,
//! #     age: u64,
//! # }
//! #
//! # type PersonRepository = Repository<Person, Directory, JsonSerializer>;
//! #
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! #     let tempdir  = tempfile::tempdir()?;
//! #     let path  = tempdir.path();
//! #     let directory = Directory::new(path)?;
//! let mut repository = PersonRepository::new(directory);
//! let mut person = Person { id: None, name: "John Smith".into(), age: 42 };
//! repository.insert(&mut person)?;
//! #     Ok(())
//! # }
//! ```
//!
//! ## Example
//!
//! This short example demonstrate how to use Dodo to read and write entities to the disk.
//!
//! ```
//! use std::error::Error;
//!
//! use serde::{Deserialize, Serialize};
//! use uuid::Uuid;
//!
//! use dodo::prelude::*;
//!
//! #[derive(Debug, Entity, Serialize, Deserialize)]
//! #[serde(rename_all = "camelCase")]
//! struct Person {
//!     id: Option<Uuid>,
//!     name: String,
//!     age: u64,
//! }
//!
//! type PersonRepository = Repository<Person, Directory, JsonSerializer>;
//!
//! fn main() -> Result<(), Box<dyn Error>> {
//!     let path = tempfile::tempdir()?;
//!
//!     let mut person1 = Person { id: None, name: "John Smith".into(), age: 18 };
//!     let mut person2 = Person { id: None, name: "Mary Smith".into(), age: 42 };
//!
//!     let mut repository = PersonRepository::new(Directory::new(&path)?);
//!     repository.insert(&mut person1)?;
//!     repository.insert(&mut person2)?;
//!
//!     println!("{:?}", repository.find_all()?.filter(|person| person.age > 20).collect()?);
//!
//!     Ok(())
//! }
//! ```
//!
//! [Entity]: entity/trait.Entity.html
//! [Storage]: storage/trait.Storage.html
//! [Directory]: storage/struct.Directory.html
//! [Serializer]: serializer/trait.Serializer.html
//! [JsonSerializer]: serializer/struct.JsonSerializer.html
//! [Repository]: repository/struct.Repository.html
//! [Serde]: https://docs.serde.rs/serde/index.html
//! [Serialize]: https://docs.serde.rs/serde/trait.Serialize.html
//! [Deserialize]: https://docs.serde.rs/serde/de/trait.DeserializeOwned.html

#![doc(html_root_url = "https://docs.rs/dodo/0.1.0")]
#![deny(missing_debug_implementations, missing_docs)]

#[cfg(feature = "derive")]
#[allow(unused_imports)]
#[macro_use]
extern crate dodo_derive;

#[cfg(feature = "derive")]
pub use dodo_derive::*;
#[doc(inline)]
pub use entity::Entity;
#[doc(inline)]
pub use repository::{Cursor, Error, Repository, Result};
#[cfg(feature = "json")]
pub use serializer::JsonSerializer;
#[doc(inline)]
pub use serializer::Serializer;
#[cfg(feature = "yaml")]
pub use serializer::YamlSerializer;
#[cfg(feature = "directory")]
pub use storage::Directory;
#[doc(inline)]
pub use storage::{Storage, Memory};

pub mod entity;
#[cfg(feature = "default")]
pub mod prelude;
pub mod repository;
pub mod serializer;
pub mod storage;