Merge pull request #277 from iSynaptic/dbvector-asref

Implementing AsRef<[u8]> for DBVector...
master
Jordan Terrell 6 years ago committed by GitHub
commit 976cd69b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/db.rs
  2. 20
      tests/test_db.rs

@ -1769,6 +1769,13 @@ impl Deref for DBVector {
} }
} }
impl AsRef<[u8]> for DBVector {
fn as_ref(&self) -> &[u8] {
// Implement this via Deref so as not to repeat ourselves
&*self
}
}
impl Drop for DBVector { impl Drop for DBVector {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {

@ -49,6 +49,26 @@ fn external() {
} }
} }
#[test]
fn db_vector_as_ref_byte_slice() {
let path = DBPath::new("_rust_rocksdb_db_vector_as_ref_byte_slice");
{
let db = DB::open_default(&path).unwrap();
assert!(db.put(b"k1", b"v1111").is_ok());
let r: Result<Option<DBVector>, Error> = db.get(b"k1");
let vector = r.unwrap().unwrap();
assert!(get_byte_slice(&vector) == b"v1111");
}
}
fn get_byte_slice<T: AsRef<[u8]>>(source: &'_ T) -> &'_ [u8] {
source.as_ref()
}
#[test] #[test]
fn errors_do_stuff() { fn errors_do_stuff() {
let path = DBPath::new("_rust_rocksdb_error"); let path = DBPath::new("_rust_rocksdb_error");

Loading…
Cancel
Save