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
use libc::c_uint;
use std::ffi::CString;
use std::ptr;
use ffi;
use error::{
lmdb_result,
Result,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Database {
dbi: ffi::MDB_dbi,
}
impl Database {
pub(crate) unsafe fn new(txn: *mut ffi::MDB_txn, name: Option<&str>, flags: c_uint) -> Result<Database> {
let c_name = name.map(|n| CString::new(n).unwrap());
let name_ptr = if let Some(ref c_name) = c_name {
c_name.as_ptr()
} else {
ptr::null()
};
let mut dbi: ffi::MDB_dbi = 0;
lmdb_result(ffi::mdb_dbi_open(txn, name_ptr, flags, &mut dbi))?;
Ok(Database {
dbi,
})
}
pub(crate) fn freelist_db() -> Database {
Database {
dbi: 0,
}
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn dbi(&self) -> ffi::MDB_dbi {
self.dbi
}
}
unsafe impl Sync for Database {}
unsafe impl Send for Database {}