Refactor Stat

without.crypto
Nan Jiang 6 years ago
parent 10697cda7b
commit 8a46f68f5f
  1. 13
      src/environment.rs
  2. 2
      src/transaction.rs

@ -162,7 +162,7 @@ impl Environment {
pub fn stat(&self) -> Result<Stat> {
unsafe {
let mut stat = Stat::new();
lmdb_try!(ffi::mdb_env_stat(self.env(), &mut stat.0));
lmdb_try!(ffi::mdb_env_stat(self.env(), stat.mdb_stat()));
Ok(stat)
}
}
@ -247,16 +247,21 @@ impl Environment {
/// Environment statistics.
///
/// Contains information about the size and layout of an LMDB environment.
pub struct Stat(pub(crate) ffi::MDB_stat);
/// Contains information about the size and layout of an LMDB environment or database.
pub struct Stat(ffi::MDB_stat);
impl Stat {
/// Create a new Stat with zero'd inner struct `ffi::MDB_stat`.
pub fn new() -> Stat {
pub(crate) fn new() -> Stat {
unsafe {
Stat(mem::zeroed())
}
}
/// Returns a mut pointer to `ffi::MDB_stat`.
pub(crate) fn mdb_stat(&mut self) -> *mut ffi::MDB_stat {
&mut self.0
}
}
impl Stat {

@ -107,7 +107,7 @@ pub trait Transaction : Sized {
fn stat(&self, db: Database) -> Result<Stat> {
unsafe {
let mut stat = Stat::new();
lmdb_try!(ffi::mdb_stat(self.txn(), db.dbi(), &mut stat.0));
lmdb_try!(ffi::mdb_stat(self.txn(), db.dbi(), stat.mdb_stat()));
Ok(stat)
}
}

Loading…
Cancel
Save