Skip to content

Commit 52b4e2a

Browse files
authored
cleanup all clippy warnings (#215)
1 parent 18561f9 commit 52b4e2a

File tree

7 files changed

+20
-24
lines changed

7 files changed

+20
-24
lines changed

examples/hello.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ fn hello_mul(_: &Context, args: Vec<RedisString>) -> RedisResult {
1818

1919
let product = nums.iter().product();
2020

21-
let mut response = Vec::from(nums);
21+
let mut response = nums;
2222
response.push(product);
2323

24-
return Ok(response.into());
24+
Ok(response.into())
2525
}
2626

2727
fn hello_err(ctx: &Context, args: Vec<RedisString>) -> RedisResult {

examples/load_unload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use redis_module::{Context, LogLevel, RedisString, Status};
55

66
static mut GLOBAL_STATE: Option<String> = None;
77

8-
fn init(ctx: &Context, args: &Vec<RedisString>) -> Status {
8+
fn init(ctx: &Context, args: &[RedisString]) -> Status {
99
let (before, after) = unsafe {
1010
let before = GLOBAL_STATE.clone();
1111
GLOBAL_STATE.replace(format!("Args passed: {}", args.join(", ")));

examples/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn timer_info(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
2727
let (remaining, data): (_, &MyData) = ctx.get_timer_info(timer_id)?;
2828
let reply = format!("Remaining: {:?}, data: {:?}", remaining, data);
2929

30-
return Ok(reply.into());
30+
Ok(reply.into())
3131
}
3232

3333
fn timer_stop(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
@@ -37,7 +37,7 @@ fn timer_stop(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
3737
let data: MyData = ctx.stop_timer(timer_id)?;
3838
let reply = format!("Data: {:?}", data);
3939

40-
return Ok(reply.into());
40+
Ok(reply.into())
4141
}
4242

4343
//////////////////////////////////////////////////////

src/context/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ impl Context {
263263
self.ctx
264264
}
265265

266+
/// # Safety
266267
#[cfg(feature = "experimental-api")]
267-
pub fn export_shared_api(
268+
pub unsafe fn export_shared_api(
268269
&self,
269270
func: *const ::std::os::raw::c_void,
270271
name: *const ::std::os::raw::c_char,
@@ -279,7 +280,7 @@ impl Context {
279280
event: &str,
280281
keyname: &RedisString,
281282
) -> raw::Status {
282-
raw::notify_keyspace_event(self.ctx, event_type, event, keyname)
283+
unsafe { raw::notify_keyspace_event(self.ctx, event_type, event, keyname) }
283284
}
284285

285286
/// Returns the redis version either by calling RedisModule_GetServerVersion API,

src/context/thread_safe.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ impl Deref for ContextGuard {
2525
/// A ThreadSafeContext can either be bound to a blocked client, or detached from any client.
2626
pub struct DetachedFromClient;
2727

28-
pub struct ThreadSafeContext<B> {
28+
pub struct ThreadSafeContext<B: Send> {
2929
pub(crate) ctx: *mut raw::RedisModuleCtx,
3030

3131
/// This field is only used implicitly by `Drop`, so avoid a compiler warning
3232
#[allow(dead_code)]
3333
blocked_client: B,
3434
}
3535

36-
unsafe impl<B> Send for ThreadSafeContext<B> {}
37-
unsafe impl<B> Sync for ThreadSafeContext<B> {}
36+
unsafe impl<B: Send> Send for ThreadSafeContext<B> {}
37+
unsafe impl<B: Send> Sync for ThreadSafeContext<B> {}
3838

3939
impl ThreadSafeContext<DetachedFromClient> {
4040
pub fn new() -> Self {
@@ -69,7 +69,7 @@ impl ThreadSafeContext<BlockedClient> {
6969
}
7070
}
7171

72-
impl<B> ThreadSafeContext<B> {
72+
impl<B: Send> ThreadSafeContext<B> {
7373
/// All other APIs require locking the context, so we wrap it in a way
7474
/// similar to `std::sync::Mutex`.
7575
pub fn lock(&self) -> ContextGuard {
@@ -79,7 +79,7 @@ impl<B> ThreadSafeContext<B> {
7979
}
8080
}
8181

82-
impl<B> Drop for ThreadSafeContext<B> {
82+
impl<B: Send> Drop for ThreadSafeContext<B> {
8383
fn drop(&mut self) {
8484
unsafe { raw::RedisModule_FreeThreadSafeContext.unwrap()(self.ctx) };
8585
}

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ macro_rules! redis_module {
122122

123123
#[no_mangle]
124124
#[allow(non_snake_case)]
125-
pub extern "C" fn RedisModule_OnLoad(
125+
pub unsafe extern "C" fn RedisModule_OnLoad(
126126
ctx: *mut $crate::raw::RedisModuleCtx,
127127
argv: *mut *mut $crate::raw::RedisModuleString,
128128
argc: std::os::raw::c_int,

src/raw.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,32 +607,27 @@ pub fn add_info_field_long_long(
607607
}
608608
}
609609

610+
/// # Safety
610611
#[cfg(feature = "experimental-api")]
611-
pub fn export_shared_api(
612+
pub unsafe fn export_shared_api(
612613
ctx: *mut RedisModuleCtx,
613614
func: *const ::std::os::raw::c_void,
614615
name: *const ::std::os::raw::c_char,
615616
) {
616-
unsafe { RedisModule_ExportSharedAPI.unwrap()(ctx, name, func as *mut ::std::os::raw::c_void) };
617+
RedisModule_ExportSharedAPI.unwrap()(ctx, name, func as *mut ::std::os::raw::c_void);
617618
}
618619

620+
/// # Safety
619621
#[cfg(feature = "experimental-api")]
620-
pub fn notify_keyspace_event(
622+
pub unsafe fn notify_keyspace_event(
621623
ctx: *mut RedisModuleCtx,
622624
event_type: NotifyEvent,
623625
event: &str,
624626
keyname: &RedisString,
625627
) -> Status {
626628
let event = CString::new(event).unwrap();
627-
unsafe {
628-
RedisModule_NotifyKeyspaceEvent.unwrap()(
629-
ctx,
630-
event_type.bits,
631-
event.as_ptr(),
632-
keyname.inner,
633-
)
629+
RedisModule_NotifyKeyspaceEvent.unwrap()(ctx, event_type.bits, event.as_ptr(), keyname.inner)
634630
.into()
635-
}
636631
}
637632

638633
#[cfg(feature = "experimental-api")]

0 commit comments

Comments
 (0)