Skip to content

Commit 67f50da

Browse files
committed
use FnMut
use FnMut
1 parent 9b1de8a commit 67f50da

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

examples/scan_keys.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ fn scan_key_foreach(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
4141
let key = ctx.open_key_with_flags(key_name, KeyFlags::NOEFFECTS | KeyFlags::NOEXPIRE | KeyFlags::ACCESS_EXPIRED );
4242
let cursor = ScanKeyCursor::new(key);
4343

44-
let res = RefCell::new(Vec::new());
44+
let mut res = Vec::new();
4545
cursor.foreach(|_key, field, value| {
46-
let mut res = res.borrow_mut();
4746
res.push(RedisValue::BulkRedisString(field.clone()));
4847
res.push(RedisValue::BulkRedisString(value.clone()));
4948
});
5049

51-
Ok(RedisValue::Array(res.take()))
50+
Ok(RedisValue::Array(res))
5251
}
5352

5453
/// Scans all fields and values in a hash key and returns them as an array of RedisString.

src/context/key_scan_cursor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl ScanKeyCursor {
8383
}
8484

8585
/// Implements a callback based foreach loop over all fields and values in the hash key, use that for optimal performance.
86-
pub fn foreach<F: Fn(&RedisKey, &RedisString, &RedisString)>(&self, f: F) {
86+
pub fn foreach<F: FnMut(&RedisKey, &RedisString, &RedisString)>(&self, f: F) {
8787
// Safety: Assumption: c-side initialized the function ptr and it is is never changed,
8888
// i.e. after module initialization the function pointers stay valid till the end of the program.
8989
let scan_key = unsafe { raw::RedisModule_ScanKey.unwrap() };
@@ -210,7 +210,7 @@ impl ScanKeyCursorIterator<'_> {
210210
///
211211
/// The `data` pointer is the closure given to [`ScanKeyCursor::foreach`] and the callback forwards
212212
/// references to the key, field and value to that closure.
213-
unsafe extern "C" fn foreach_callback<F: Fn(&RedisKey, &RedisString, &RedisString)>(
213+
unsafe extern "C" fn foreach_callback<F: FnMut(&RedisKey, &RedisString, &RedisString)>(
214214
key: *mut raw::RedisModuleKey,
215215
field: *mut raw::RedisModuleString,
216216
value: *mut raw::RedisModuleString,

0 commit comments

Comments
 (0)