From 8a46f68f5fab8de8cc41ca227707dfb310184290 Mon Sep 17 00:00:00 2001 From: Nan Jiang Date: Thu, 4 Apr 2019 12:53:04 -0400 Subject: [PATCH] Refactor Stat --- src/environment.rs | 13 +++++++++---- src/transaction.rs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index 74fb882..e31d9f1 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -162,7 +162,7 @@ impl Environment { pub fn stat(&self) -> Result { 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 { diff --git a/src/transaction.rs b/src/transaction.rs index 97eecc1..78175b1 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -107,7 +107,7 @@ pub trait Transaction : Sized { fn stat(&self, db: Database) -> Result { 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) } }