Revert "Allow to pass in owned variable for Decision::Change variant in compaction filter (#725)"

This reverts commit 5ed1043488.
master
Oleksandr Anyshchenko 2 years ago
parent b8b4cf3161
commit dc18b52148
  1. 7
      src/compaction_filter.rs
  2. 2
      tests/test_compationfilter.rs

@ -28,7 +28,7 @@ pub enum Decision {
/// Remove the object from the database /// Remove the object from the database
Remove, Remove,
/// Change the value for the key /// Change the value for the key
Change(Vec<u8>), Change(&'static [u8]),
} }
/// CompactionFilter allows an application to modify/delete a key-value at /// 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 /// [set_compaction_filter]: ../struct.Options.html#method.set_compaction_filter
pub trait CompactionFilterFn: FnMut(u32, &[u8], &[u8]) -> Decision {} pub trait CompactionFilterFn: FnMut(u32, &[u8], &[u8]) -> Decision {}
impl<F> CompactionFilterFn for F where F: FnMut(u32, &[u8], &[u8]) -> Decision + Send + 'static {} impl<F> CompactionFilterFn for F where F: FnMut(u32, &[u8], &[u8]) -> Decision + Send + 'static {}
pub struct CompactionFilterCallback<F> pub struct CompactionFilterCallback<F>
@ -136,8 +135,8 @@ where
Keep => 0, Keep => 0,
Remove => 1, Remove => 1,
Change(newval) => { Change(newval) => {
*new_value = newval.as_ptr() as *mut c_char;
*new_value_length = newval.len() as size_t; *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; *value_changed = 1_u8;
0 0
} }
@ -150,7 +149,7 @@ fn test_filter(level: u32, key: &[u8], value: &[u8]) -> Decision {
use self::Decision::{Change, Keep, Remove}; use self::Decision::{Change, Keep, Remove};
match key.first() { match key.first() {
Some(&b'_') => Remove, Some(&b'_') => Remove,
Some(&b'%') => Change(b"secret".to_vec()), Some(&b'%') => Change(b"secret"),
_ => Keep, _ => Keep,
} }
} }

@ -25,7 +25,7 @@ fn test_filter(level: u32, key: &[u8], value: &[u8]) -> CompactionDecision {
use self::CompactionDecision::*; use self::CompactionDecision::*;
match key.first() { match key.first() {
Some(&b'_') => Remove, Some(&b'_') => Remove,
Some(&b'%') => Change(b"secret".to_vec()), Some(&b'%') => Change(b"secret"),
_ => Keep, _ => Keep,
} }
} }

Loading…
Cancel
Save