diff --git a/src/compaction_filter.rs b/src/compaction_filter.rs index cd2a7d2..fc52068 100644 --- a/src/compaction_filter.rs +++ b/src/compaction_filter.rs @@ -28,7 +28,7 @@ pub enum Decision { /// Remove the object from the database Remove, /// Change the value for the key - Change(Vec), + Change(&'static [u8]), } /// CompactionFilter allows an application to modify/delete a key-value at @@ -73,7 +73,6 @@ pub trait CompactionFilter { /// /// [set_compaction_filter]: ../struct.Options.html#method.set_compaction_filter pub trait CompactionFilterFn: FnMut(u32, &[u8], &[u8]) -> Decision {} - impl CompactionFilterFn for F where F: FnMut(u32, &[u8], &[u8]) -> Decision + Send + 'static {} pub struct CompactionFilterCallback @@ -136,8 +135,8 @@ where Keep => 0, Remove => 1, Change(newval) => { + *new_value = newval.as_ptr() as *mut c_char; *new_value_length = newval.len() as size_t; - *new_value = Box::into_raw(newval.into_boxed_slice()) as *mut c_char; *value_changed = 1_u8; 0 } @@ -150,7 +149,7 @@ fn test_filter(level: u32, key: &[u8], value: &[u8]) -> Decision { use self::Decision::{Change, Keep, Remove}; match key.first() { Some(&b'_') => Remove, - Some(&b'%') => Change(b"secret".to_vec()), + Some(&b'%') => Change(b"secret"), _ => Keep, } } diff --git a/tests/test_compationfilter.rs b/tests/test_compationfilter.rs index 3562366..f5e206d 100644 --- a/tests/test_compationfilter.rs +++ b/tests/test_compationfilter.rs @@ -25,7 +25,7 @@ fn test_filter(level: u32, key: &[u8], value: &[u8]) -> CompactionDecision { use self::CompactionDecision::*; match key.first() { Some(&b'_') => Remove, - Some(&b'%') => Change(b"secret".to_vec()), + Some(&b'%') => Change(b"secret"), _ => Keep, } }