From 22b34a40cb9ca18c0f97b7a567621c53c669318d Mon Sep 17 00:00:00 2001 From: Martin Ek Date: Sun, 27 Jan 2019 22:18:01 +0000 Subject: [PATCH] Add property_value functions --- src/db.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/db.rs b/src/db.rs index c51f9b0..6ec9f0c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1152,6 +1152,27 @@ impl DB { )) }) } + + pub fn property_value(&self, name: &str) -> Option { + let prop_name = CString::new(name).unwrap(); + unsafe { + let value = ffi::rocksdb_property_value(self.inner, prop_name.as_ptr()); + if value.is_null() { + return None; + } + + let s = CStr::from_ptr(value).to_str().unwrap().to_owned(); + libc::free(value as *mut c_void); + Some(s) + } + } + + pub fn property_int_value(&self, name: &str) -> Option { + match self.property_value(name) { + Some(value) => value.parse::().ok(), + None => None, + } + } } impl WriteBatch {