Skip to content

Commit

Permalink
Revert "Allow to pass in owned variable for Decision::Change variant …
Browse files Browse the repository at this point in the history
…in compaction filter (rust-rocksdb#725)"

This reverts commit 5ed1043.
  • Loading branch information
aleksuss committed Feb 9, 2023
1 parent b8b4cf3 commit dc18b52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/compaction_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Decision {
/// Remove the object from the database
Remove,
/// Change the value for the key
Change(Vec<u8>),
Change(&'static [u8]),
}

/// CompactionFilter allows an application to modify/delete a key-value at
Expand Down Expand Up @@ -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<F> CompactionFilterFn for F where F: FnMut(u32, &[u8], &[u8]) -> Decision + Send + 'static {}

pub struct CompactionFilterCallback<F>
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compationfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit dc18b52

Please sign in to comment.