From 562f413f4c3b3f78f4f39f02f1705a7ef091dcf7 Mon Sep 17 00:00:00 2001 From: Jordan Terrell Date: Wed, 13 Feb 2019 07:11:18 -0600 Subject: [PATCH 1/2] Making DB.create_cf generic... --- src/db.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db.rs b/src/db.rs index b871d87..16fec63 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1027,8 +1027,8 @@ impl DB { self.get_pinned_cf_opt(cf, key, &ReadOptions::default()) } - pub fn create_cf(&self, name: &str, opts: &Options) -> Result { - let cname = match CString::new(name.as_bytes()) { + pub fn create_cf>(&self, name: N, opts: &Options) -> Result { + let cname = match CString::new(name.as_ref().as_bytes()) { Ok(c) => c, Err(_) => { return Err(Error::new( @@ -1048,7 +1048,7 @@ impl DB { self.cfs .write() .map_err(|e| Error::new(e.to_string()))? - .insert(name.to_string(), cf_handle); + .insert(name.as_ref().to_string(), cf_handle); ColumnFamily { inner: cf_handle, From ca1c76b2de16b8da7b2a387688a46fc1c421ed5b Mon Sep 17 00:00:00 2001 From: Jordan Terrell Date: Wed, 13 Feb 2019 07:11:56 -0600 Subject: [PATCH 2/2] Add test to prove creating duplicate column family results in error... --- tests/test_column_family.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_column_family.rs b/tests/test_column_family.rs index c9c44f2..7350ddf 100644 --- a/tests/test_column_family.rs +++ b/tests/test_column_family.rs @@ -238,3 +238,20 @@ fn test_column_family_with_options() { } } } + +#[test] +fn test_create_duplicate_column_family() { + let n = DBPath::new("_rust_rocksdb_create_duplicate_column_family"); + { + let mut opts = Options::default(); + opts.create_if_missing(true); + opts.create_missing_column_families(true); + + let db = match DB::open_cf(&opts, &n, &["cf1"]) { + Ok(d) => d, + Err(e) => panic!("failed to create new column family: {}", e), + }; + + assert!(db.create_cf("cf1", &opts).is_err()); + } +}