cleanup slice creation

without.crypto
Dan Burkert 10 years ago
parent d27d6a493e
commit 52d663fcf9
  1. 7
      src/cursor.rs
  2. 2
      src/lib.rs
  3. 14
      src/transaction.rs

@ -1,5 +1,5 @@
use libc::{c_void, size_t, c_uint};
use std::{mem, ptr, raw};
use std::{ptr, slice};
use std::marker::{PhantomData, PhantomFn};
use database::Database;
@ -206,10 +206,7 @@ unsafe fn slice_to_val(slice: Option<&[u8]>) -> ffi::MDB_val {
}
unsafe fn val_to_slice<'a>(val: ffi::MDB_val) -> &'a [u8] {
mem::transmute(raw::Slice {
data: val.mv_data as *const u8,
len: val.mv_size as usize
})
slice::from_raw_parts(val.mv_data as *const u8, val.mv_size as usize)
}
pub struct Iter<'txn> {

@ -1,7 +1,7 @@
//! Idiomatic and safe APIs for interacting with the
//! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/).
#![feature(core, libc, optin_builtin_traits, unsafe_destructor)]
#![feature(libc, optin_builtin_traits, unsafe_destructor)]
#![cfg_attr(test, feature(std_misc, test))]
extern crate libc;

@ -1,5 +1,5 @@
use libc::{c_uint, c_void, size_t};
use std::{mem, ptr, raw};
use std::{mem, ptr, slice};
use std::marker::{PhantomData, PhantomFn} ;
use ffi;
@ -77,10 +77,8 @@ pub trait TransactionExt<'env> : Transaction<'env> + Sized {
unsafe {
match ffi::mdb_get(self.txn(), database.dbi(), &mut key_val, &mut data_val) {
ffi::MDB_SUCCESS => {
Ok(mem::transmute(raw::Slice {
data: data_val.mv_data as *const u8,
len: data_val.mv_size as usize
}))
Ok(slice::from_raw_parts(data_val.mv_data as *const u8,
data_val.mv_size as usize))
},
err_code => Err(Error::from_err_code(err_code)),
}
@ -290,10 +288,8 @@ impl <'env> RwTransaction<'env> {
&mut key_val,
&mut data_val,
flags.bits() | ffi::MDB_RESERVE)));
Ok(mem::transmute(raw::Slice {
data: data_val.mv_data as *const u8,
len: data_val.mv_size as usize
}))
Ok(slice::from_raw_parts_mut(data_val.mv_data as *mut u8,
data_val.mv_size as usize))
}
}

Loading…
Cancel
Save