clean up String

master
Tyler Neely 10 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;
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");

@ -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(

@ -57,13 +57,13 @@ pub struct 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();
opts.create_if_missing(true);
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 {
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<RocksdbVector, String> = db.get(b"k1");

Loading…
Cancel
Save