From d856b804c0f42c310804eb5d15c0f5aa0da650c9 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 27 May 2016 20:28:38 +0800 Subject: [PATCH 1/2] save path for later use --- src/rocksdb.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 93fcff7..928b212 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -31,6 +31,7 @@ use rocksdb_options::{Options, WriteOptions}; pub struct DB { inner: rocksdb_ffi::DBInstance, cfs: BTreeMap, + path: String, } unsafe impl Send for DB {} @@ -375,6 +376,7 @@ impl DB { Ok(DB { inner: db, cfs: cf_map, + path: path.to_owned(), }) } @@ -412,6 +414,10 @@ impl DB { Ok(()) } + pub fn path(&self) -> &str { + &self.path + } + pub fn write_opt(&self, batch: WriteBatch, writeopts: &WriteOptions) From 7b2e1b91a7deddcb4095139fc3f278b34b387cd0 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 27 Oct 2016 10:20:24 +0100 Subject: [PATCH 2/2] Implement Debug for DB --- src/rocksdb.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 928b212..5b1a301 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -22,6 +22,7 @@ use std::ops::Deref; use std::path::Path; use std::slice; use std::str::from_utf8; +use std::fmt; use self::libc::size_t; @@ -784,6 +785,12 @@ impl Drop for DB { } } +impl fmt::Debug for DB { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "RocksDB {{ path: {:?} }}", self.path()) + } +} + impl Writable for WriteBatch { /// Insert a value into the database under the given key fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> {