From 15fe40a8e3372c1df6bbdce9ce56fee09209a5f7 Mon Sep 17 00:00:00 2001 From: "Craig M. Brandenburg" Date: Sun, 2 Jul 2017 18:02:59 -0700 Subject: [PATCH] Implement Debug for public types (#16) --- src/cursor.rs | 26 +++++++++++++++++++++++++- src/environment.rs | 8 +++++++- src/transaction.rs | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/cursor.rs b/src/cursor.rs index aa26746..b3f59a2 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -1,5 +1,5 @@ use libc::{c_void, size_t, c_uint}; -use std::{ptr, slice}; +use std::{fmt, ptr, result, slice}; use std::marker::PhantomData; use database::Database; @@ -108,6 +108,12 @@ impl <'txn> Cursor<'txn> for RoCursor<'txn> { } } +impl <'txn> fmt::Debug for RoCursor<'txn> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("RoCursor").finish() + } +} + impl <'txn> Drop for RoCursor<'txn> { fn drop(&mut self) { unsafe { ffi::mdb_cursor_close(self.cursor) } @@ -141,6 +147,12 @@ impl <'txn> Cursor<'txn> for RwCursor<'txn> { } } +impl <'txn> fmt::Debug for RwCursor<'txn> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("RwCursor").finish() + } +} + impl <'txn> Drop for RwCursor<'txn> { fn drop(&mut self) { unsafe { ffi::mdb_cursor_close(self.cursor) } @@ -217,6 +229,12 @@ impl <'txn> Iter<'txn> { } } +impl <'txn> fmt::Debug for Iter<'txn> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("Iter").finish() + } +} + impl <'txn> Iterator for Iter<'txn> { type Item = (&'txn [u8], &'txn [u8]); @@ -257,6 +275,12 @@ impl <'txn> IterDup<'txn> { } } +impl <'txn> fmt::Debug for IterDup<'txn> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("IterDup").finish() + } +} + impl <'txn> Iterator for IterDup<'txn> { type Item = Iter<'txn>; diff --git a/src/environment.rs b/src/environment.rs index 80251d1..c800bd5 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -1,11 +1,11 @@ use libc::{c_uint, size_t}; +use std::{fmt, ptr, result}; use std::ffi::CString; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; #[cfg(windows)] use std::ffi::OsStr; use std::path::Path; -use std::ptr; use std::sync::Mutex; use ffi; @@ -156,6 +156,12 @@ impl Environment { unsafe impl Send for Environment {} unsafe impl Sync for Environment {} +impl fmt::Debug for Environment { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("Environment").finish() + } +} + impl Drop for Environment { fn drop(&mut self) { unsafe { ffi::mdb_env_close(self.env) } diff --git a/src/transaction.rs b/src/transaction.rs index ab481a4..b5278d8 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -1,5 +1,5 @@ use libc::{c_uint, c_void, size_t}; -use std::{mem, ptr, slice}; +use std::{fmt, mem, ptr, result, slice}; use std::marker::PhantomData ; use ffi; @@ -110,6 +110,12 @@ pub struct RoTransaction<'env> { _marker: PhantomData<&'env ()>, } +impl <'env> fmt::Debug for RoTransaction<'env> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("RoTransaction").finish() + } +} + impl <'env> Drop for RoTransaction<'env> { fn drop(&mut self) { unsafe { ffi::mdb_txn_abort(self.txn) } @@ -166,6 +172,12 @@ pub struct InactiveTransaction<'env> { _marker: PhantomData<&'env ()>, } +impl <'env> fmt::Debug for InactiveTransaction<'env> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("InactiveTransaction").finish() + } +} + impl <'env> Drop for InactiveTransaction<'env> { fn drop(&mut self) { unsafe { ffi::mdb_txn_abort(self.txn) } @@ -195,6 +207,12 @@ pub struct RwTransaction<'env> { _marker: PhantomData<&'env ()>, } +impl <'env> fmt::Debug for RwTransaction<'env> { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.debug_struct("RwTransaction").finish() + } +} + impl <'env> Drop for RwTransaction<'env> { fn drop(&mut self) { unsafe { ffi::mdb_txn_abort(self.txn) }