Skip to content

Commit 4fdbb23

Browse files
authored
Clean all clippy warnings (RedisJSON#621)
* clean all clippy warnings * replace Vec with []
1 parent 79cd916 commit 4fdbb23

File tree

7 files changed

+28
-23
lines changed

7 files changed

+28
-23
lines changed

src/c_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ macro_rules! redis_json_module_export_shared_api {
530530
&JSONAPI as *const RedisJSONAPI_V1 as *const c_void,
531531
REDISJSON_GETAPI.as_ptr() as *const c_char,
532532
);
533-
}
533+
};
534534
}
535535

536536
static JSONAPI: RedisJSONAPI_V1 = RedisJSONAPI_V1 {

src/commands.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ where
762762

763763
/// Sort the paths so higher indices precede lower indices on the same array,
764764
/// And if one path is a sub-path of the other, then paths with shallower hierarchy (closer to the top-level) precedes paths with deeper hierarchy
765-
fn prepare_paths_for_deletion(paths: &mut Vec<Vec<String>>) {
765+
fn prepare_paths_for_deletion(paths: &mut [Vec<String>]) {
766766
paths.sort_by(|v1, v2| {
767767
v1.iter()
768768
.zip_longest(v2.iter())

src/ivalue_manager.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct IValueKeyHolderWrite<'a> {
3737
/// If the returned value from `func` is [`Err`], the current value remains (although it could be modified by `func`)
3838
///
3939
fn replace<F: FnMut(&mut IValue) -> Result<Option<IValue>, Error>>(
40-
path: &Vec<String>,
40+
path: &[String],
4141
root: &mut IValue,
4242
mut func: F,
4343
) -> Result<(), Error> {
@@ -53,8 +53,8 @@ fn replace<F: FnMut(&mut IValue) -> Result<Option<IValue>, Error>>(
5353
let obj = target_once.as_object_mut().unwrap();
5454
if is_last {
5555
if let Entry::Occupied(mut e) = obj.entry(token) {
56-
let mut v = e.get_mut();
57-
match (func)(&mut v) {
56+
let v = e.get_mut();
57+
match (func)(v) {
5858
Ok(res) => {
5959
if let Some(res) = res {
6060
*v = res;
@@ -75,8 +75,8 @@ fn replace<F: FnMut(&mut IValue) -> Result<Option<IValue>, Error>>(
7575
if let Ok(x) = token.parse::<usize>() {
7676
if is_last {
7777
if x < arr.len() {
78-
let mut v = &mut arr.as_mut_slice()[x];
79-
match (func)(&mut v) {
78+
let v = &mut arr.as_mut_slice()[x];
79+
match (func)(v) {
8080
Ok(res) => {
8181
if let Some(res) = res {
8282
*v = res;
@@ -115,7 +115,7 @@ fn replace<F: FnMut(&mut IValue) -> Result<Option<IValue>, Error>>(
115115
/// If the returned value from `func` is [`Err`], the current value remains (although it could be modified by `func`)
116116
///
117117
fn update<F: FnMut(&mut IValue) -> Result<Option<()>, Error>>(
118-
path: &Vec<String>,
118+
path: &[String],
119119
root: &mut IValue,
120120
mut func: F,
121121
) -> Result<(), Error> {
@@ -130,8 +130,8 @@ fn update<F: FnMut(&mut IValue) -> Result<Option<()>, Error>>(
130130
let obj = target_once.as_object_mut().unwrap();
131131
if is_last {
132132
if let Entry::Occupied(mut e) = obj.entry(token) {
133-
let mut v = e.get_mut();
134-
match (func)(&mut v) {
133+
let v = e.get_mut();
134+
match (func)(v) {
135135
Ok(res) => {
136136
if res.is_none() {
137137
e.remove();
@@ -149,8 +149,8 @@ fn update<F: FnMut(&mut IValue) -> Result<Option<()>, Error>>(
149149
if let Ok(x) = token.parse::<usize>() {
150150
if is_last {
151151
if x < arr.len() {
152-
let mut v = &mut arr.as_mut_slice()[x];
153-
match (func)(&mut v) {
152+
let v = &mut arr.as_mut_slice()[x];
153+
match (func)(v) {
154154
Ok(res) => {
155155
if res.is_none() {
156156
arr.remove(x);
@@ -186,8 +186,8 @@ impl<'a> IValueKeyHolderWrite<'a> {
186186
{
187187
if paths.is_empty() {
188188
// updating the root require special treatment
189-
let mut root = self.get_value().unwrap().unwrap();
190-
let res = (op_fun)(&mut root);
189+
let root = self.get_value().unwrap().unwrap();
190+
let res = (op_fun)(root);
191191
match res {
192192
Ok(res) => {
193193
if res.is_none() {
@@ -446,7 +446,7 @@ impl<'a> WriteHolder<IValue, IValue> for IValueKeyHolderWrite<'a> {
446446
fn arr_insert(
447447
&mut self,
448448
paths: Vec<String>,
449-
args: &Vec<IValue>,
449+
args: &[IValue],
450450
index: i64,
451451
) -> Result<usize, RedisError> {
452452
let mut res = None;

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ macro_rules! redis_json_module_create {(
422422
pre_command_function: $pre_command_function_expr,
423423
}
424424

425-
fn intialize(ctx: &Context, args: &Vec<RedisString>) -> Status {
425+
fn intialize(ctx: &Context, args: &[RedisString]) -> Status {
426426
ctx.log_notice(&format!("version: {} git sha: {} branch: {}",
427427
$version,
428428
match GIT_SHA { Some(val) => val, _ => "unknown"},
@@ -434,7 +434,7 @@ macro_rules! redis_json_module_create {(
434434
$init_func(ctx, args)
435435
}
436436

437-
fn json_init_config(ctx: &Context, args: &Vec<RedisString>) -> Status{
437+
fn json_init_config(ctx: &Context, args: &[RedisString]) -> Status{
438438
if args.len() % 2 != 0 {
439439
ctx.log(LogLevel::Warning, "RedisJson arguments must be key:value pairs");
440440
return Status::Err;
@@ -495,10 +495,10 @@ macro_rules! redis_json_module_create {(
495495
}
496496

497497
#[cfg(not(feature = "as-library"))]
498-
const fn pre_command(_ctx: &Context, _args: &Vec<RedisString>) {}
498+
const fn pre_command(_ctx: &Context, _args: &[RedisString]) {}
499499

500500
#[cfg(not(feature = "as-library"))]
501-
const fn dummy_init(_ctx: &Context, _args: &Vec<RedisString>) -> Status {
501+
const fn dummy_init(_ctx: &Context, _args: &[RedisString]) -> Status {
502502
Status::Ok
503503
}
504504

src/manager.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait WriteHolder<O: Clone, V: SelectValue> {
5555
fn arr_insert(
5656
&mut self,
5757
path: Vec<String>,
58-
args: &Vec<O>,
58+
args: &[O],
5959
index: i64,
6060
) -> Result<usize, RedisError>;
6161
fn arr_pop(&mut self, path: Vec<String>, index: i64) -> Result<Option<String>, RedisError>;
@@ -84,6 +84,7 @@ pub trait Manager {
8484
ctx: &Context,
8585
key: RedisString,
8686
) -> Result<Self::WriteHolder, RedisError>;
87+
#[allow(clippy::wrong_self_convention)]
8788
fn from_str(&self, val: &str, format: Format) -> Result<Self::O, Error>;
8889
fn get_memory(&self, v: &Self::V) -> Result<usize, RedisError>;
8990
fn is_json(&self, key: *mut RedisModuleKey) -> Result<bool, RedisError>;
@@ -122,7 +123,7 @@ pub struct KeyHolderWrite<'a> {
122123
}
123124

124125
fn update<F: FnMut(Value) -> Result<Option<Value>, Error>>(
125-
path: &Vec<String>,
126+
path: &[String],
126127
root: &mut Value,
127128
mut func: F,
128129
) -> Result<(), Error> {
@@ -423,7 +424,7 @@ impl<'a> WriteHolder<Value, Value> for KeyHolderWrite<'a> {
423424
fn arr_insert(
424425
&mut self,
425426
paths: Vec<String>,
426-
args: &Vec<Value>,
427+
args: &[Value],
427428
index: i64,
428429
) -> Result<usize, RedisError> {
429430
let mut res = None;
@@ -437,7 +438,7 @@ impl<'a> WriteHolder<Value, Value> for KeyHolderWrite<'a> {
437438
let index = index as usize;
438439
let mut new_value = v.take();
439440
let curr = new_value.as_array_mut().unwrap();
440-
curr.splice(index..index, args.clone());
441+
curr.splice(index..index, args.to_owned());
441442
res = Some(curr.len());
442443
Ok(Some(new_value))
443444
})?;

src/nodevisitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl Display for StaticPathElement {
2020
}
2121
}
2222

23+
#[allow(clippy::enum_variant_names)]
2324
#[derive(Debug, PartialEq)]
2425
pub enum VisitStatus {
2526
NotValid,

src/redisjson.rs

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub mod type_methods {
186186
})
187187
}
188188

189+
/// # Safety
189190
#[allow(non_snake_case, unused)]
190191
pub unsafe extern "C" fn free(value: *mut c_void) {
191192
if value.is_null() {
@@ -206,6 +207,7 @@ pub mod type_methods {
206207
};
207208
}
208209

210+
/// # Safety
209211
#[allow(non_snake_case, unused)]
210212
pub unsafe extern "C" fn rdb_save(rdb: *mut raw::RedisModuleIO, value: *mut c_void) {
211213
let mut out = serde_json::Serializer::new(Vec::new());
@@ -225,6 +227,7 @@ pub mod type_methods {
225227
raw::save_string(rdb, cjson.to_str().unwrap());
226228
}
227229

230+
/// # Safety
228231
#[allow(non_snake_case, unused)]
229232
pub unsafe extern "C" fn mem_usage(value: *const c_void) -> usize {
230233
match get_manager_type() {

0 commit comments

Comments
 (0)