Skip to content

Commit 9d82962

Browse files
committed
Merge branch 'rukai-clippy_fix'
2 parents 17707a7 + 73674b2 commit 9d82962

File tree

14 files changed

+266
-292
lines changed

14 files changed

+266
-292
lines changed

rust/benches/j4rs_benchmark.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn do_invocation_w_string_args(jvm: &Jvm, instance: &Instance) -> Instance {
2121
jvm.invoke(
2222
instance,
2323
"echo",
24-
&vec![InvocationArg::try_from("a").unwrap()],
24+
&[InvocationArg::try_from("a").unwrap()],
2525
)
2626
.unwrap()
2727
}
@@ -30,7 +30,7 @@ fn do_invocation_w_integer_args(jvm: &Jvm, instance: &Instance) -> Instance {
3030
jvm.invoke(
3131
instance,
3232
"echo",
33-
&vec![InvocationArg::try_from(33_i32).unwrap()],
33+
&[InvocationArg::try_from(33_i32).unwrap()],
3434
)
3535
.unwrap()
3636
}
@@ -40,7 +40,7 @@ fn do_invocation_w_string_args_and_to_rust(jvm: &Jvm, instance: &Instance) {
4040
.invoke(
4141
instance,
4242
"getMyWithArgs",
43-
&vec![InvocationArg::try_from("a").unwrap()],
43+
&[InvocationArg::try_from("a").unwrap()],
4444
)
4545
.unwrap();
4646
let _: String = jvm.to_rust(s_instance).unwrap();
@@ -51,16 +51,14 @@ fn use_to_rust_deserialized(jvm: &Jvm, instance: &Instance) {
5151
.invoke(
5252
instance,
5353
"addInts",
54-
&vec![
55-
InvocationArg::try_from(30_i32)
54+
&[InvocationArg::try_from(30_i32)
5655
.unwrap()
5756
.into_primitive()
5857
.unwrap(),
5958
InvocationArg::try_from(3_i32)
6059
.unwrap()
6160
.into_primitive()
62-
.unwrap(),
63-
],
61+
.unwrap()],
6462
)
6563
.unwrap();
6664
let _: i32 = jvm.to_rust_deserialized(i_instance).unwrap();
@@ -71,16 +69,14 @@ fn use_to_rust_boxed(jvm: &Jvm, instance: &Instance) {
7169
.invoke(
7270
instance,
7371
"addInts",
74-
&vec![
75-
InvocationArg::try_from(30_i32)
72+
&[InvocationArg::try_from(30_i32)
7673
.unwrap()
7774
.into_primitive()
7875
.unwrap(),
7976
InvocationArg::try_from(3_i32)
8077
.unwrap()
8178
.into_primitive()
82-
.unwrap(),
83-
],
79+
.unwrap()],
8480
)
8581
.unwrap();
8682
let _: Box<i32> = jvm.to_rust_boxed(i_instance).unwrap();

rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn copy_jars_from_java(jar_source_path: &Path) -> Result<(), J4rsBuildError> {
8484

8585
// Copy only if the files are not the same
8686
let do_copy = if destination_jar_file.exists() {
87-
!are_same_files(&jar_source_path, &destination_jar_file).unwrap_or(true)
87+
!are_same_files(jar_source_path, &destination_jar_file).unwrap_or(true)
8888
} else {
8989
true
9090
};

rust/src/api/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Instance {
101101
Ok(Instance {
102102
class_name: self.class_name.clone(),
103103
jinstance: jni_utils::_create_weak_global_ref_from_global_ref(
104-
self.jinstance.clone(),
104+
self.jinstance,
105105
cache::get_thread_local_env()?,
106106
)?,
107107
skip_deleting_jobject: false,
@@ -191,7 +191,7 @@ impl<'a> ChainableInstance<'a> {
191191
instance: &Instance,
192192
jvm: &'a Jvm,
193193
) -> errors::Result<ChainableInstance<'a>> {
194-
let cloned = jvm.clone_instance(&instance)?;
194+
let cloned = jvm.clone_instance(instance)?;
195195
Ok(ChainableInstance {
196196
instance: cloned,
197197
jvm,
@@ -265,7 +265,7 @@ mod instance_unit_tests {
265265
"isNull",
266266
&[InvocationArg::try_from(maybe_null)?])?;
267267
let is_null: bool = jvm.to_rust(is_null)?;
268-
assert_eq!(is_null, true);
268+
assert!(is_null);
269269
Ok(())
270270
}
271271

rust/src/api/invocation_arg.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::ptr;
1818

1919
use jni_sys::{jobject, JNIEnv};
2020
use serde::Serialize;
21-
use serde_json;
2221

2322
use crate::api::instance::Instance;
2423
use crate::api::{JavaClass, Jvm, Null};
@@ -153,7 +152,7 @@ impl InvocationArg {
153152
} else {
154153
let json = serde_json::to_string(arg)?;
155154
Ok(InvocationArg::Rust {
156-
json: json,
155+
json,
157156
class_name: class_name.to_string(),
158157
serialized: true,
159158
})
@@ -163,18 +162,18 @@ impl InvocationArg {
163162
fn make_primitive(&mut self) -> errors::Result<()> {
164163
match utils::primitive_of(self) {
165164
Some(primitive_repr) => {
166-
match self {
167-
&mut InvocationArg::Java {
165+
match *self {
166+
InvocationArg::Java {
168167
instance: _,
169168
ref mut class_name,
170169
serialized: _,
171170
} => *class_name = primitive_repr,
172-
&mut InvocationArg::Rust {
171+
InvocationArg::Rust {
173172
json: _,
174173
ref mut class_name,
175174
serialized: _,
176175
} => *class_name = primitive_repr,
177-
&mut InvocationArg::RustBasic {
176+
InvocationArg::RustBasic {
178177
instance: _,
179178
ref mut class_name,
180179
serialized: _,
@@ -184,7 +183,7 @@ impl InvocationArg {
184183
}
185184
None => Err(errors::J4RsError::JavaError(format!(
186185
"Cannot transform to primitive: {}",
187-
utils::get_class_name(&self)
186+
utils::get_class_name(self)
188187
))),
189188
}
190189
}
@@ -203,13 +202,13 @@ impl InvocationArg {
203202
pub fn as_java_ptr_with_global_ref(&self, jni_env: *mut JNIEnv) -> errors::Result<jobject> {
204203
match self {
205204
_s @ &InvocationArg::Java { .. } => {
206-
jni_utils::invocation_arg_jobject_from_java(&self, jni_env, true)
205+
jni_utils::invocation_arg_jobject_from_java(self, jni_env, true)
207206
}
208207
_s @ &InvocationArg::Rust { .. } => {
209-
jni_utils::invocation_arg_jobject_from_rust_serialized(&self, jni_env, true)
208+
jni_utils::invocation_arg_jobject_from_rust_serialized(self, jni_env, true)
210209
}
211210
_s @ &InvocationArg::RustBasic { .. } => {
212-
jni_utils::invocation_arg_jobject_from_rust_basic(&self, jni_env, true)
211+
jni_utils::invocation_arg_jobject_from_rust_basic(self, jni_env, true)
213212
}
214213
}
215214
}
@@ -218,13 +217,13 @@ impl InvocationArg {
218217
pub fn as_java_ptr_with_local_ref(&self, jni_env: *mut JNIEnv) -> errors::Result<jobject> {
219218
match self {
220219
_s @ &InvocationArg::Java { .. } => {
221-
jni_utils::invocation_arg_jobject_from_java(&self, jni_env, false)
220+
jni_utils::invocation_arg_jobject_from_java(self, jni_env, false)
222221
}
223222
_s @ &InvocationArg::Rust { .. } => {
224-
jni_utils::invocation_arg_jobject_from_rust_serialized(&self, jni_env, false)
223+
jni_utils::invocation_arg_jobject_from_rust_serialized(self, jni_env, false)
225224
}
226225
_s @ &InvocationArg::RustBasic { .. } => {
227-
jni_utils::invocation_arg_jobject_from_rust_basic(&self, jni_env, false)
226+
jni_utils::invocation_arg_jobject_from_rust_basic(self, jni_env, false)
228227
}
229228
}
230229
}
@@ -233,30 +232,26 @@ impl InvocationArg {
233232
pub fn instance(self) -> errors::Result<Instance> {
234233
match self {
235234
InvocationArg::Java { instance: i, .. } => Ok(i),
236-
InvocationArg::RustBasic { .. } => Err(errors::J4RsError::RustError(format!(
237-
"Invalid operation: Cannot get the instance of an InvocationArg::RustBasic"
238-
))),
239-
InvocationArg::Rust { .. } => Err(errors::J4RsError::RustError(format!(
240-
"Cannot get the instance from an InvocationArg::Rust"
241-
))),
235+
InvocationArg::RustBasic { .. } => Err(errors::J4RsError::RustError("Invalid operation: Cannot get the instance of an InvocationArg::RustBasic".to_string())),
236+
InvocationArg::Rust { .. } => Err(errors::J4RsError::RustError("Cannot get the instance from an InvocationArg::Rust".to_string())),
242237
}
243238
}
244239

245240
pub fn class_name(&self) -> &str {
246241
match self {
247-
&InvocationArg::Java {
242+
InvocationArg::Java {
248243
instance: _,
249-
ref class_name,
244+
class_name,
250245
serialized: _,
251246
} => class_name,
252-
&InvocationArg::Rust {
247+
InvocationArg::Rust {
253248
json: _,
254-
ref class_name,
249+
class_name,
255250
serialized: _,
256251
} => class_name,
257-
&InvocationArg::RustBasic {
252+
InvocationArg::RustBasic {
258253
instance: _,
259-
ref class_name,
254+
class_name,
260255
serialized: _,
261256
} => class_name,
262257
}
@@ -291,8 +286,8 @@ impl From<Instance> for InvocationArg {
291286
let class_name = instance.class_name.to_owned();
292287

293288
InvocationArg::Java {
294-
instance: instance,
295-
class_name: class_name,
289+
instance,
290+
class_name,
296291
serialized: false,
297292
}
298293
}
@@ -331,7 +326,7 @@ impl<'a> TryFrom<&'a [String]> for InvocationArg {
331326
fn try_from(vec: &'a [String]) -> errors::Result<InvocationArg> {
332327
let args: errors::Result<Vec<InvocationArg>> = vec
333328
.iter()
334-
.map(|elem| InvocationArg::try_from(elem))
329+
.map(InvocationArg::try_from)
335330
.collect();
336331
let res =
337332
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -379,7 +374,7 @@ impl<'a> TryFrom<&'a [bool]> for InvocationArg {
379374
fn try_from(vec: &'a [bool]) -> errors::Result<InvocationArg> {
380375
let args: errors::Result<Vec<InvocationArg>> = vec
381376
.iter()
382-
.map(|elem| InvocationArg::try_from(elem))
377+
.map(InvocationArg::try_from)
383378
.collect();
384379
let res =
385380
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -399,7 +394,7 @@ impl<'a> TryFrom<&'a [i8]> for InvocationArg {
399394
fn try_from(vec: &'a [i8]) -> errors::Result<InvocationArg> {
400395
let args: errors::Result<Vec<InvocationArg>> = vec
401396
.iter()
402-
.map(|elem| InvocationArg::try_from(elem))
397+
.map(InvocationArg::try_from)
403398
.collect();
404399
let res =
405400
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -423,7 +418,7 @@ impl<'a> TryFrom<&'a [char]> for InvocationArg {
423418
fn try_from(vec: &'a [char]) -> errors::Result<InvocationArg> {
424419
let args: errors::Result<Vec<InvocationArg>> = vec
425420
.iter()
426-
.map(|elem| InvocationArg::try_from(elem))
421+
.map(InvocationArg::try_from)
427422
.collect();
428423
let res =
429424
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -447,7 +442,7 @@ impl<'a> TryFrom<&'a [i16]> for InvocationArg {
447442
fn try_from(vec: &'a [i16]) -> errors::Result<InvocationArg> {
448443
let args: errors::Result<Vec<InvocationArg>> = vec
449444
.iter()
450-
.map(|elem| InvocationArg::try_from(elem))
445+
.map(InvocationArg::try_from)
451446
.collect();
452447
let res =
453448
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -471,7 +466,7 @@ impl<'a> TryFrom<&'a [u16]> for InvocationArg {
471466
fn try_from(vec: &'a [u16]) -> errors::Result<InvocationArg> {
472467
let args: errors::Result<Vec<InvocationArg>> = vec
473468
.iter()
474-
.map(|elem| InvocationArg::try_from(elem))
469+
.map(InvocationArg::try_from)
475470
.collect();
476471
let res =
477472
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -495,7 +490,7 @@ impl<'a> TryFrom<&'a [i32]> for InvocationArg {
495490
fn try_from(vec: &'a [i32]) -> errors::Result<InvocationArg> {
496491
let args: errors::Result<Vec<InvocationArg>> = vec
497492
.iter()
498-
.map(|elem| InvocationArg::try_from(elem))
493+
.map(InvocationArg::try_from)
499494
.collect();
500495
let res =
501496
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -515,7 +510,7 @@ impl<'a> TryFrom<&'a [i64]> for InvocationArg {
515510
fn try_from(vec: &'a [i64]) -> errors::Result<InvocationArg> {
516511
let args: errors::Result<Vec<InvocationArg>> = vec
517512
.iter()
518-
.map(|elem| InvocationArg::try_from(elem))
513+
.map(InvocationArg::try_from)
519514
.collect();
520515
let res =
521516
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -539,7 +534,7 @@ impl<'a> TryFrom<&'a [f32]> for InvocationArg {
539534
fn try_from(vec: &'a [f32]) -> errors::Result<InvocationArg> {
540535
let args: errors::Result<Vec<InvocationArg>> = vec
541536
.iter()
542-
.map(|elem| InvocationArg::try_from(elem))
537+
.map(InvocationArg::try_from)
543538
.collect();
544539
let res =
545540
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
@@ -563,7 +558,7 @@ impl<'a> TryFrom<&'a [f64]> for InvocationArg {
563558
fn try_from(vec: &'a [f64]) -> errors::Result<InvocationArg> {
564559
let args: errors::Result<Vec<InvocationArg>> = vec
565560
.iter()
566-
.map(|elem| InvocationArg::try_from(elem))
561+
.map(InvocationArg::try_from)
567562
.collect();
568563
let res =
569564
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);

0 commit comments

Comments
 (0)