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
//! Fully typed ORM based on libmdbx.
//!
//! Much simpler in usage but slightly more limited.
//!
//! ```rust,no_run
//! use libmdbx::orm::{table, table_info, DatabaseChart, Decodable, Encodable};
//! use std::sync::Arc;
//! use once_cell::sync::Lazy;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
//! pub struct UserInfo {
//! pub age: u8,
//! pub first_name: String,
//! pub last_name: String,
//! }
//!
//! impl Encodable for UserInfo {
//! type Encoded = Vec<u8>;
//!
//! fn encode(self) -> Self::Encoded {
//! // Here we define serialization of UserInfo
//! # todo!()
//! }
//! }
//!
//! impl Decodable for UserInfo {
//! fn decode(v: &[u8]) -> anyhow::Result<Self> {
//! // Here we define deserialization of UserInfo
//! # todo!()
//! }
//! }
//!
//! // Define the users table
//! table!(
//! /// Table with users info.
//! ( Users ) String => UserInfo
//! );
//!
//! // Assemble database chart
//! pub static TABLES: Lazy<Arc<DatabaseChart>> =
//! Lazy::new(|| Arc::new([table_info!(Users)].into_iter().collect()));
//!
//! // Create database with the database chart
//! let db = Arc::new(libmdbx::orm::Database::create(None, &TABLES).unwrap());
//!
//! let users = vec![
//! (
//! "l33tc0der".to_string(),
//! UserInfo {
//! age: 42,
//! first_name: "Leet".to_string(),
//! last_name: "Coder".to_string(),
//! },
//! ),
//! (
//! "lameguy".to_string(),
//! UserInfo {
//! age: 25,
//! first_name: "Lame".to_string(),
//! last_name: "Guy".to_string(),
//! },
//! ),
//! ];
//!
//! let tx = db.begin_readwrite().unwrap();
//!
//! let mut cursor = tx.cursor::<Users>().unwrap();
//!
//! // Insert user info into table
//! for (nickname, user_info) in &users {
//! cursor.upsert(nickname.clone(), user_info.clone()).unwrap();
//! }
//!
//! // Walk over table and collect its contents
//! assert_eq!(
//! users,
//! cursor.walk(None).collect::<anyhow::Result<Vec<_>>>().unwrap()
//! );
//! ```
pub use ;
pub use crate::;