Update docs and small tweaks

without.crypto
Dan Burkert 6 years ago
parent e5dbfc81bb
commit 09af4d92b7
  1. 5
      src/cursor.rs
  2. 24
      src/environment.rs
  3. 5
      src/error.rs
  4. 9
      src/flags.rs
  5. 3
      src/lib.rs

@ -212,6 +212,7 @@ unsafe fn val_to_slice<'a>(val: ffi::MDB_val) -> &'a [u8] {
slice::from_raw_parts(val.mv_data as *const u8, val.mv_size as usize)
}
/// An iterator over the values in an LMDB database.
pub struct Iter<'txn> {
cursor: *mut ffi::MDB_cursor,
op: c_uint,
@ -259,6 +260,10 @@ impl <'txn> Iterator for Iter<'txn> {
}
}
/// An iterator over the keys and duplicate values in an LMDB database.
///
/// The yielded items of the iterator are themselves iterators over the duplicate values for a
/// specific key.
pub struct IterDup<'txn> {
cursor: *mut ffi::MDB_cursor,
op: c_uint,

@ -35,11 +35,6 @@ pub struct Environment {
dbi_open_mutex: Mutex<()>,
}
/// Database statistics
///
/// Contains information about the size and layout of an LMDB database
pub struct Stat(ffi::MDB_stat);
impl Environment {
/// Creates a new builder for specifying options for opening an LMDB environment.
@ -109,6 +104,9 @@ impl Environment {
Ok(db)
}
/// Retrieves the set of flags which the database is opened with.
///
/// The database must belong to to this environment.
pub fn get_db_flags<'env>(&'env self, db: Database) -> Result<DatabaseFlags> {
let txn = self.begin_ro_txn()?;
let mut flags: c_uint = 0;
@ -157,7 +155,7 @@ impl Environment {
ffi::mdb_dbi_close(self.env, db.dbi());
}
/// Get database statistics.
/// Retrieves statistics about this environment.
pub fn stat(&self) -> Result<Stat> {
unsafe {
let mut stat = Stat(mem::zeroed());
@ -167,14 +165,19 @@ impl Environment {
}
}
/// Environment statistics.
///
/// Contains information about the size and layout of an LMDB environment.
pub struct Stat(ffi::MDB_stat);
impl Stat {
/// Size of database in bytes.
/// Size of a database page. This is the same for all databases in the environment.
#[inline]
pub fn size(&self) -> u32 {
pub fn page_size(&self) -> u32 {
self.0.ms_psize
}
/// Height of B-tree.
/// Depth (height) of the B-tree.
#[inline]
pub fn depth(&self) -> u32 {
self.0.ms_depth
@ -186,7 +189,7 @@ impl Stat {
self.0.ms_branch_pages
}
/// Number of lead pages.
/// Number of leaf pages.
#[inline]
pub fn leaf_pages(&self) -> usize {
self.0.ms_leaf_pages
@ -276,6 +279,7 @@ impl EnvironmentBuilder {
}
/// Sets the provided options in the environment.
pub fn set_flags(&mut self, flags: EnvironmentFlags) -> &mut EnvironmentBuilder {
self.flags = flags;
self

@ -6,6 +6,7 @@ use std::{fmt, result, str};
use ffi;
/// An LMDB error kind.
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum Error {
/// key/data pair already exists.
@ -53,6 +54,8 @@ pub enum Error {
}
impl Error {
/// Converts a raw error code to an `Error`.
pub fn from_err_code(err_code: c_int) -> Error {
match err_code {
ffi::MDB_KEYEXIST => Error::KeyExist,
@ -79,6 +82,7 @@ impl Error {
}
}
/// Converts an `Error` to the raw error code.
pub fn to_err_code(&self) -> c_int {
match *self {
Error::KeyExist => ffi::MDB_KEYEXIST,
@ -122,6 +126,7 @@ impl StdError for Error {
}
}
/// An LMDB result.
pub type Result<T> = result::Result<T, Error>;
pub fn lmdb_result(err_code: c_int) -> Result<()> {

@ -3,7 +3,8 @@ use libc::c_uint;
use ffi::*;
bitflags! {
#[doc="Environment Options"]
#[doc="Environment options."]
#[derive(Default)]
pub struct EnvironmentFlags: c_uint {
#[doc="Use a fixed address for the mmap region. This flag must be specified"]
@ -103,7 +104,8 @@ bitflags! {
}
bitflags! {
#[doc="Database Options"]
#[doc="Database options."]
#[derive(Default)]
pub struct DatabaseFlags: c_uint {
#[doc="Keys are strings to be compared in reverse order, from the end of the strings"]
@ -138,7 +140,8 @@ bitflags! {
}
bitflags! {
#[doc="Write Options"]
#[doc="Write options."]
#[derive(Default)]
pub struct WriteFlags: c_uint {
#[doc="Insert the new item only if the key does not already appear in the database."]

@ -1,8 +1,9 @@
//! Idiomatic and safe APIs for interacting with the
//! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/).
//! [Lightning Memory-mapped Database (LMDB)](https://symas.com/lmdb).
#![cfg_attr(test, feature(test))]
#![deny(warnings)]
#![deny(missing_docs)]
#![doc(html_root_url = "https://docs.rs/lmdb/0.7.2")]
extern crate libc;

Loading…
Cancel
Save