clean up String

master
Tyler Neely 11 years ago
parent eb3acf0991
commit e08f60e535
  1. 2
      README.md
  2. 6
      src/main.rs
  3. 6
      src/rocksdb.rs

@ -14,7 +14,7 @@ extern crate rocksdb;
use rocksdb::Rocksdb; use rocksdb::Rocksdb;
fn main() { fn main() {
match Rocksdb::open_default("/path/for/rocksdb/storage".to_string()) { match Rocksdb::open_default("/path/for/rocksdb/storage") {
Ok(db) => { Ok(db) => {
db.put(b"my key", b"my value"); db.put(b"my key", b"my value");

@ -5,7 +5,7 @@ use test::Bencher;
#[allow(dead_code)] #[allow(dead_code)]
fn main() { fn main() {
match Rocksdb::open_default("/tmp/rust-rocksdb".to_string()) { match Rocksdb::open_default("/tmp/rust-rocksdb") {
Ok(db) => { Ok(db) => {
assert!(db.put(b"my key", b"my value").is_ok()); assert!(db.put(b"my key", b"my value").is_ok());
@ -31,7 +31,7 @@ fn main() {
#[allow(dead_code)] #[allow(dead_code)]
#[bench] #[bench]
fn writes(b: &mut Bencher) { 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; let mut i = 0 as u64;
b.iter(|| { b.iter(|| {
db.put(i.to_string().as_bytes(), b"v1111"); db.put(i.to_string().as_bytes(), b"v1111");
@ -43,7 +43,7 @@ fn writes(b: &mut Bencher) {
#[allow(dead_code)] #[allow(dead_code)]
#[bench] #[bench]
fn reads(b: &mut Bencher) { 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; let mut i = 0 as u64;
b.iter(|| { b.iter(|| {
db.get(i.to_string().as_bytes()).on_error( db.get(i.to_string().as_bytes()).on_error(

@ -57,13 +57,13 @@ pub struct Rocksdb {
} }
impl Rocksdb { impl Rocksdb {
pub fn open_default(path: String) -> Result<Rocksdb, String> { pub fn open_default(path: &str) -> Result<Rocksdb, String> {
let opts = RocksdbOptions::new(); let opts = RocksdbOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
Rocksdb::open(opts, path) Rocksdb::open(opts, path)
} }
pub fn open(opts: RocksdbOptions, path: String) -> Result<Rocksdb, String> { pub fn open(opts: RocksdbOptions, path: &str) -> Result<Rocksdb, String> {
unsafe { unsafe {
let cpath = path.to_c_str(); let cpath = path.to_c_str();
let cpath_ptr = cpath.as_ptr(); let cpath_ptr = cpath.as_ptr();
@ -280,7 +280,7 @@ impl <'a,T,E> RocksdbResult<'a,T,E> {
#[allow(dead_code)] #[allow(dead_code)]
#[test] #[test]
fn external() { 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"); let p = db.put(b"k1", b"v1111");
assert!(p.is_ok()); assert!(p.is_ok());
let r: RocksdbResult<RocksdbVector, String> = db.get(b"k1"); let r: RocksdbResult<RocksdbVector, String> = db.get(b"k1");

Loading…
Cancel
Save