diff --git a/README.md b/README.md index c4818d1..89e6c05 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ extern crate rocksdb; use rocksdb::Rocksdb; fn main() { - match Rocksdb::open_default("/path/for/rocksdb/storage".to_string()) { + match Rocksdb::open_default("/path/for/rocksdb/storage") { Ok(db) => { db.put(b"my key", b"my value"); diff --git a/src/main.rs b/src/main.rs index dc1180b..578b408 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use test::Bencher; #[allow(dead_code)] fn main() { - match Rocksdb::open_default("/tmp/rust-rocksdb".to_string()) { + match Rocksdb::open_default("/tmp/rust-rocksdb") { Ok(db) => { assert!(db.put(b"my key", b"my value").is_ok()); @@ -31,7 +31,7 @@ fn main() { #[allow(dead_code)] #[bench] fn writes(b: &mut Bencher) { - let db = open("testdb".to_string(), true).unwrap(); + let db = Rocksdb::open_default("testdb").unwrap(); let mut i = 0 as u64; b.iter(|| { db.put(i.to_string().as_bytes(), b"v1111"); @@ -43,7 +43,7 @@ fn writes(b: &mut Bencher) { #[allow(dead_code)] #[bench] fn reads(b: &mut Bencher) { - let db = open("testdb".to_string(), true).unwrap(); + let db = Rocksdb::open_default("testdb").unwrap(); let mut i = 0 as u64; b.iter(|| { db.get(i.to_string().as_bytes()).on_error( diff --git a/src/rocksdb.rs b/src/rocksdb.rs index efb7e92..bb4dfde 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -57,13 +57,13 @@ pub struct Rocksdb { } impl Rocksdb { - pub fn open_default(path: String) -> Result { + pub fn open_default(path: &str) -> Result { let opts = RocksdbOptions::new(); opts.create_if_missing(true); Rocksdb::open(opts, path) } - pub fn open(opts: RocksdbOptions, path: String) -> Result { + pub fn open(opts: RocksdbOptions, path: &str) -> Result { unsafe { let cpath = path.to_c_str(); let cpath_ptr = cpath.as_ptr(); @@ -280,7 +280,7 @@ impl <'a,T,E> RocksdbResult<'a,T,E> { #[allow(dead_code)] #[test] fn external() { - let db = open("externaltest".to_string(), true).unwrap(); + let db = Rocksdb::open_default("externaltest").unwrap(); let p = db.put(b"k1", b"v1111"); assert!(p.is_ok()); let r: RocksdbResult = db.get(b"k1");