Skip to content

Commit 250e986

Browse files
authored
Clippy pedantic (#163)
* add next_str (cherry picked from commit 693ac9d) * clean some pedantic warnings
1 parent 70e5e80 commit 250e986

File tree

7 files changed

+109
-19
lines changed

7 files changed

+109
-19
lines changed

src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct RedisAlloc;
88
unsafe impl GlobalAlloc for RedisAlloc {
99
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
1010
let size = (layout.size() + layout.align() - 1) & (!(layout.align() - 1));
11-
raw::RedisModule_Alloc.unwrap()(size) as *mut u8
11+
raw::RedisModule_Alloc.unwrap()(size).cast::<u8>()
1212
}
1313

1414
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
15-
raw::RedisModule_Free.unwrap()(ptr as *mut c_void)
15+
raw::RedisModule_Free.unwrap()(ptr.cast::<c_void>())
1616
}
1717
}

src/context/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ impl Context {
5353
self.log(LogLevel::Warning, message);
5454
}
5555

56+
/// # Panics
57+
///
58+
/// Will panic if `RedisModule_AutoMemory` is missing in redismodule.h
5659
pub fn auto_memory(&self) {
5760
unsafe {
5861
raw::RedisModule_AutoMemory.unwrap()(self.ctx);
5962
}
6063
}
6164

65+
/// # Panics
66+
///
67+
/// Will panic if `RedisModule_IsKeysPositionRequest` is missing in redismodule.h
6268
pub fn is_keys_position_request(&self) -> bool {
6369
// We want this to be available in tests where we don't have an actual Redis to call
6470
if cfg!(feature = "test") {
@@ -70,6 +76,9 @@ impl Context {
7076
result != 0
7177
}
7278

79+
/// # Panics
80+
///
81+
/// Will panic if `RedisModule_KeyAtPos` is missing in redismodule.h
7382
pub fn key_at_pos(&self, pos: i32) {
7483
// TODO: This will crash redis if `pos` is out of range.
7584
// Think of a way to make this safe by checking the range.
@@ -125,6 +134,9 @@ impl Context {
125134
}
126135
}
127136

137+
/// # Panics
138+
///
139+
/// Will panic if methods used are missing in redismodule.h
128140
pub fn reply(&self, r: RedisResult) -> raw::Status {
129141
match r {
130142
Ok(RedisValue::Integer(v)) => unsafe {

src/key.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ impl RedisKey {
4242
RedisKey { ctx, key_inner }
4343
}
4444

45+
/// # Panics
46+
///
47+
/// Will panic if `RedisModule_ModuleTypeGetValue` is missing in redismodule.h
4548
pub fn get_value<T>(&self, redis_type: &RedisType) -> Result<Option<&T>, RedisError> {
4649
verify_type(self.key_inner, redis_type)?;
4750

4851
let value =
49-
unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner) as *mut T };
52+
unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner).cast::<T>() };
5053

5154
if value.is_null() {
5255
return Ok(None);
@@ -57,6 +60,9 @@ impl RedisKey {
5760
Ok(Some(value))
5861
}
5962

63+
/// # Panics
64+
///
65+
/// Will panic if `RedisModule_KeyType` is missing in redismodule.h
6066
pub fn key_type(&self) -> raw::KeyType {
6167
unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into()
6268
}
@@ -247,11 +253,17 @@ impl RedisKeyWritable {
247253
}
248254
}
249255

256+
/// # Panics
257+
///
258+
/// Will panic if `RedisModule_DeleteKey` is missing in redismodule.h
250259
pub fn delete(&self) -> RedisResult {
251260
unsafe { raw::RedisModule_DeleteKey.unwrap()(self.key_inner) };
252261
REDIS_OK
253262
}
254263

264+
/// # Panics
265+
///
266+
/// Will panic if `RedisModule_KeyType` is missing in redismodule.h
255267
pub fn key_type(&self) -> raw::KeyType {
256268
unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into()
257269
}
@@ -268,13 +280,16 @@ impl RedisKeyWritable {
268280
RedisKeyWritable { ctx, key_inner }
269281
}
270282

283+
/// # Panics
284+
///
285+
/// Will panic if `RedisModule_ModuleTypeGetValue` is missing in redismodule.h
271286
pub fn get_value<'a, 'b, T>(
272287
&'a self,
273288
redis_type: &RedisType,
274289
) -> Result<Option<&'b mut T>, RedisError> {
275290
verify_type(self.key_inner, redis_type)?;
276291
let value =
277-
unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner) as *mut T };
292+
unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner).cast::<T>() };
278293

279294
if value.is_null() {
280295
return Ok(None);
@@ -284,9 +299,12 @@ impl RedisKeyWritable {
284299
Ok(Some(value))
285300
}
286301

302+
/// # Panics
303+
///
304+
/// Will panic if `RedisModule_ModuleTypeSetValue` is missing in redismodule.h
287305
pub fn set_value<T>(&self, redis_type: &RedisType, value: T) -> Result<(), RedisError> {
288306
verify_type(self.key_inner, redis_type)?;
289-
let value = Box::into_raw(Box::new(value)) as *mut c_void;
307+
let value = Box::into_raw(Box::new(value)).cast::<c_void>();
290308
let status: raw::Status = unsafe {
291309
raw::RedisModule_ModuleTypeSetValue.unwrap()(
292310
self.key_inner,
@@ -358,7 +376,7 @@ where
358376

359377
/// Provides an iterator over the multi-get results in the form of (field-name, field-value)
360378
/// pairs. The type of field-name elements is the same as that passed to the original multi-
361-
/// get call, while the field-value elements may be of any type for which a RedisString `Into`
379+
/// get call, while the field-value elements may be of any type for which a `RedisString` `Into`
362380
/// conversion is implemented.
363381
///
364382
/// # Examples
@@ -462,6 +480,10 @@ fn to_raw_mode(mode: KeyMode) -> raw::KeyMode {
462480
}
463481
}
464482

483+
/// # Panics
484+
///
485+
/// Will panic if `RedisModule_KeyType` or `RedisModule_ModuleTypeGetType` are missing in redismodule.h
486+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
465487
pub fn verify_type(key_inner: *mut raw::RedisModuleKey, redis_type: &RedisType) -> RedisResult {
466488
let key_type: KeyType = unsafe { raw::RedisModule_KeyType.unwrap()(key_inner) }.into();
467489

src/native_types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl RedisType {
2929
}
3030
}
3131

32+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
3233
pub fn create_data_type(&self, ctx: *mut raw::RedisModuleCtx) -> Result<(), &str> {
3334
if self.name.len() != 9 {
3435
let msg = "Redis requires the length of native type names to be exactly 9 characters";
@@ -64,6 +65,7 @@ impl RedisType {
6465
}
6566

6667
// TODO: Move to raw
68+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
6769
pub fn redis_log(ctx: *mut raw::RedisModuleCtx, msg: &str) {
6870
let level = CString::new("notice").unwrap(); // FIXME reuse this
6971
let msg = CString::new(msg).unwrap();

0 commit comments

Comments
 (0)