Skip to content

Commit

Permalink
Merge branch 'rukai-clippy_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
astonbitecode committed Oct 30, 2024
2 parents 17707a7 + 73674b2 commit 9d82962
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 292 deletions.
18 changes: 7 additions & 11 deletions rust/benches/j4rs_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn do_invocation_w_string_args(jvm: &Jvm, instance: &Instance) -> Instance {
jvm.invoke(
instance,
"echo",
&vec![InvocationArg::try_from("a").unwrap()],
&[InvocationArg::try_from("a").unwrap()],
)
.unwrap()
}
Expand All @@ -30,7 +30,7 @@ fn do_invocation_w_integer_args(jvm: &Jvm, instance: &Instance) -> Instance {
jvm.invoke(
instance,
"echo",
&vec![InvocationArg::try_from(33_i32).unwrap()],
&[InvocationArg::try_from(33_i32).unwrap()],
)
.unwrap()
}
Expand All @@ -40,7 +40,7 @@ fn do_invocation_w_string_args_and_to_rust(jvm: &Jvm, instance: &Instance) {
.invoke(
instance,
"getMyWithArgs",
&vec![InvocationArg::try_from("a").unwrap()],
&[InvocationArg::try_from("a").unwrap()],
)
.unwrap();
let _: String = jvm.to_rust(s_instance).unwrap();
Expand All @@ -51,16 +51,14 @@ fn use_to_rust_deserialized(jvm: &Jvm, instance: &Instance) {
.invoke(
instance,
"addInts",
&vec![
InvocationArg::try_from(30_i32)
&[InvocationArg::try_from(30_i32)
.unwrap()
.into_primitive()
.unwrap(),
InvocationArg::try_from(3_i32)
.unwrap()
.into_primitive()
.unwrap(),
],
.unwrap()],
)
.unwrap();
let _: i32 = jvm.to_rust_deserialized(i_instance).unwrap();
Expand All @@ -71,16 +69,14 @@ fn use_to_rust_boxed(jvm: &Jvm, instance: &Instance) {
.invoke(
instance,
"addInts",
&vec![
InvocationArg::try_from(30_i32)
&[InvocationArg::try_from(30_i32)
.unwrap()
.into_primitive()
.unwrap(),
InvocationArg::try_from(3_i32)
.unwrap()
.into_primitive()
.unwrap(),
],
.unwrap()],
)
.unwrap();
let _: Box<i32> = jvm.to_rust_boxed(i_instance).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn copy_jars_from_java(jar_source_path: &Path) -> Result<(), J4rsBuildError> {

// Copy only if the files are not the same
let do_copy = if destination_jar_file.exists() {
!are_same_files(&jar_source_path, &destination_jar_file).unwrap_or(true)
!are_same_files(jar_source_path, &destination_jar_file).unwrap_or(true)
} else {
true
};
Expand Down
6 changes: 3 additions & 3 deletions rust/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Instance {
Ok(Instance {
class_name: self.class_name.clone(),
jinstance: jni_utils::_create_weak_global_ref_from_global_ref(
self.jinstance.clone(),
self.jinstance,
cache::get_thread_local_env()?,
)?,
skip_deleting_jobject: false,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<'a> ChainableInstance<'a> {
instance: &Instance,
jvm: &'a Jvm,
) -> errors::Result<ChainableInstance<'a>> {
let cloned = jvm.clone_instance(&instance)?;
let cloned = jvm.clone_instance(instance)?;
Ok(ChainableInstance {
instance: cloned,
jvm,
Expand Down Expand Up @@ -265,7 +265,7 @@ mod instance_unit_tests {
"isNull",
&[InvocationArg::try_from(maybe_null)?])?;
let is_null: bool = jvm.to_rust(is_null)?;
assert_eq!(is_null, true);
assert!(is_null);
Ok(())
}

Expand Down
69 changes: 32 additions & 37 deletions rust/src/api/invocation_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::ptr;

use jni_sys::{jobject, JNIEnv};
use serde::Serialize;
use serde_json;

use crate::api::instance::Instance;
use crate::api::{JavaClass, Jvm, Null};
Expand Down Expand Up @@ -153,7 +152,7 @@ impl InvocationArg {
} else {
let json = serde_json::to_string(arg)?;
Ok(InvocationArg::Rust {
json: json,
json,
class_name: class_name.to_string(),
serialized: true,
})
Expand All @@ -163,18 +162,18 @@ impl InvocationArg {
fn make_primitive(&mut self) -> errors::Result<()> {
match utils::primitive_of(self) {
Some(primitive_repr) => {
match self {
&mut InvocationArg::Java {
match *self {
InvocationArg::Java {
instance: _,
ref mut class_name,
serialized: _,
} => *class_name = primitive_repr,
&mut InvocationArg::Rust {
InvocationArg::Rust {
json: _,
ref mut class_name,
serialized: _,
} => *class_name = primitive_repr,
&mut InvocationArg::RustBasic {
InvocationArg::RustBasic {
instance: _,
ref mut class_name,
serialized: _,
Expand All @@ -184,7 +183,7 @@ impl InvocationArg {
}
None => Err(errors::J4RsError::JavaError(format!(
"Cannot transform to primitive: {}",
utils::get_class_name(&self)
utils::get_class_name(self)
))),
}
}
Expand All @@ -203,13 +202,13 @@ impl InvocationArg {
pub fn as_java_ptr_with_global_ref(&self, jni_env: *mut JNIEnv) -> errors::Result<jobject> {
match self {
_s @ &InvocationArg::Java { .. } => {
jni_utils::invocation_arg_jobject_from_java(&self, jni_env, true)
jni_utils::invocation_arg_jobject_from_java(self, jni_env, true)
}
_s @ &InvocationArg::Rust { .. } => {
jni_utils::invocation_arg_jobject_from_rust_serialized(&self, jni_env, true)
jni_utils::invocation_arg_jobject_from_rust_serialized(self, jni_env, true)
}
_s @ &InvocationArg::RustBasic { .. } => {
jni_utils::invocation_arg_jobject_from_rust_basic(&self, jni_env, true)
jni_utils::invocation_arg_jobject_from_rust_basic(self, jni_env, true)
}
}
}
Expand All @@ -218,13 +217,13 @@ impl InvocationArg {
pub fn as_java_ptr_with_local_ref(&self, jni_env: *mut JNIEnv) -> errors::Result<jobject> {
match self {
_s @ &InvocationArg::Java { .. } => {
jni_utils::invocation_arg_jobject_from_java(&self, jni_env, false)
jni_utils::invocation_arg_jobject_from_java(self, jni_env, false)
}
_s @ &InvocationArg::Rust { .. } => {
jni_utils::invocation_arg_jobject_from_rust_serialized(&self, jni_env, false)
jni_utils::invocation_arg_jobject_from_rust_serialized(self, jni_env, false)
}
_s @ &InvocationArg::RustBasic { .. } => {
jni_utils::invocation_arg_jobject_from_rust_basic(&self, jni_env, false)
jni_utils::invocation_arg_jobject_from_rust_basic(self, jni_env, false)
}
}
}
Expand All @@ -233,30 +232,26 @@ impl InvocationArg {
pub fn instance(self) -> errors::Result<Instance> {
match self {
InvocationArg::Java { instance: i, .. } => Ok(i),
InvocationArg::RustBasic { .. } => Err(errors::J4RsError::RustError(format!(
"Invalid operation: Cannot get the instance of an InvocationArg::RustBasic"
))),
InvocationArg::Rust { .. } => Err(errors::J4RsError::RustError(format!(
"Cannot get the instance from an InvocationArg::Rust"
))),
InvocationArg::RustBasic { .. } => Err(errors::J4RsError::RustError("Invalid operation: Cannot get the instance of an InvocationArg::RustBasic".to_string())),
InvocationArg::Rust { .. } => Err(errors::J4RsError::RustError("Cannot get the instance from an InvocationArg::Rust".to_string())),
}
}

pub fn class_name(&self) -> &str {
match self {
&InvocationArg::Java {
InvocationArg::Java {
instance: _,
ref class_name,
class_name,
serialized: _,
} => class_name,
&InvocationArg::Rust {
InvocationArg::Rust {
json: _,
ref class_name,
class_name,
serialized: _,
} => class_name,
&InvocationArg::RustBasic {
InvocationArg::RustBasic {
instance: _,
ref class_name,
class_name,
serialized: _,
} => class_name,
}
Expand Down Expand Up @@ -291,8 +286,8 @@ impl From<Instance> for InvocationArg {
let class_name = instance.class_name.to_owned();

InvocationArg::Java {
instance: instance,
class_name: class_name,
instance,
class_name,
serialized: false,
}
}
Expand Down Expand Up @@ -331,7 +326,7 @@ impl<'a> TryFrom<&'a [String]> for InvocationArg {
fn try_from(vec: &'a [String]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand Down Expand Up @@ -379,7 +374,7 @@ impl<'a> TryFrom<&'a [bool]> for InvocationArg {
fn try_from(vec: &'a [bool]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -399,7 +394,7 @@ impl<'a> TryFrom<&'a [i8]> for InvocationArg {
fn try_from(vec: &'a [i8]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -423,7 +418,7 @@ impl<'a> TryFrom<&'a [char]> for InvocationArg {
fn try_from(vec: &'a [char]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -447,7 +442,7 @@ impl<'a> TryFrom<&'a [i16]> for InvocationArg {
fn try_from(vec: &'a [i16]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -471,7 +466,7 @@ impl<'a> TryFrom<&'a [u16]> for InvocationArg {
fn try_from(vec: &'a [u16]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -495,7 +490,7 @@ impl<'a> TryFrom<&'a [i32]> for InvocationArg {
fn try_from(vec: &'a [i32]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -515,7 +510,7 @@ impl<'a> TryFrom<&'a [i64]> for InvocationArg {
fn try_from(vec: &'a [i64]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -539,7 +534,7 @@ impl<'a> TryFrom<&'a [f32]> for InvocationArg {
fn try_from(vec: &'a [f32]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand All @@ -563,7 +558,7 @@ impl<'a> TryFrom<&'a [f64]> for InvocationArg {
fn try_from(vec: &'a [f64]) -> errors::Result<InvocationArg> {
let args: errors::Result<Vec<InvocationArg>> = vec
.iter()
.map(|elem| InvocationArg::try_from(elem))
.map(InvocationArg::try_from)
.collect();
let res =
Jvm::do_create_java_list(cache::get_thread_local_env()?, cache::J4RS_ARRAY, &args?);
Expand Down
Loading

0 comments on commit 9d82962

Please sign in to comment.