Skip to content

Resolve more clippy lints #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions rust/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,13 @@ impl<'a> ChainableInstance<'a> {
}

/// Returns the Rust representation of the provided instance
pub fn to_rust<T: Any>(self) -> errors::Result<T>
where
T: DeserializeOwned,
pub fn to_rust<T: Any + DeserializeOwned>(self) -> errors::Result<T>
{
self.jvm.to_rust(self.instance)
}

/// Returns the Rust representation of the provided instance, boxed
pub fn to_rust_boxed<T: Any>(self) -> errors::Result<Box<T>>
where
T: DeserializeOwned,
pub fn to_rust_boxed<T: Any + DeserializeOwned>(self) -> errors::Result<Box<T>>
{
self.jvm.to_rust_boxed(self.instance)
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/api/invocation_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl<'a> TryFrom<&'a u16> for InvocationArg {
}
}

impl<'a, 'b> TryFrom<&'a i32> for InvocationArg {
impl<'a> TryFrom<&'a i32> for InvocationArg {
type Error = errors::J4RsError;
fn try_from(arg: &'a i32) -> errors::Result<InvocationArg> {
InvocationArg::new_2(
Expand Down
26 changes: 12 additions & 14 deletions rust/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,9 +1631,8 @@ impl Jvm {
pub fn select(instance_receivers: &[&InstanceReceiver]) -> errors::Result<(usize, Instance)> {
loop {
for (index, ir) in instance_receivers.iter().enumerate() {
let res = ir.rx.try_recv();
if res.is_ok() {
return Ok((index, res.unwrap()));
if let Ok(res) = ir.rx.try_recv() {
return Ok((index, res));
}
}
thread::yield_now();
Expand All @@ -1653,9 +1652,8 @@ impl Jvm {
let start = time::Instant::now();
loop {
for (index, ir) in instance_receivers.iter().enumerate() {
let res = ir.rx.try_recv();
if res.is_ok() {
return Ok((index, res.unwrap()));
if let Ok(res) = ir.rx.try_recv() {
return Ok((index, res));
}
}
if &start.elapsed() > timeout {
Expand Down Expand Up @@ -1836,7 +1834,7 @@ impl<'a> JvmBuilder<'a> {
self.classpath_entries
.iter()
.fold(".".to_string(), |all, elem| {
format!("{}{}{}", all, utils::classpath_sep(), elem.to_string())
format!("{}{}{}", all, utils::classpath_sep(), elem)
})
} else {
// The default classpath contains all the jars in the jassets directory
Expand Down Expand Up @@ -1866,7 +1864,7 @@ impl<'a> JvmBuilder<'a> {
self.classpath_entries
.iter()
.fold(default_class_path, |all, elem| {
format!("{}{}{}", all, utils::classpath_sep(), elem.to_string())
format!("{}{}{}", all, utils::classpath_sep(), elem)
})
};
info(&format!("Setting classpath to {}", classpath));
Expand Down Expand Up @@ -2058,9 +2056,9 @@ impl<'a> ClasspathEntry<'a> {
}
}

impl<'a> ToString for ClasspathEntry<'a> {
fn to_string(&self) -> String {
self.0.to_string()
impl<'a> std::fmt::Display for ClasspathEntry<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

Expand All @@ -2074,9 +2072,9 @@ impl<'a> JavaOpt<'a> {
}
}

impl<'a> ToString for JavaOpt<'a> {
fn to_string(&self) -> String {
self.0.to_string()
impl<'a> std::fmt::Display for JavaOpt<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

Expand Down
6 changes: 3 additions & 3 deletions rust/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ macro_rules! get_cached {
} else {
None
};
if jopt.is_none() {
if let Some(jopt) = jopt {
Ok(jopt)
} else {
let j = { $do_retrieve };
if CLASS_CACHING_ENABLED {
$setter_name(j);
}
Ok(j)
} else {
Ok(jopt.unwrap())
}
}};
}
Expand Down
9 changes: 0 additions & 9 deletions rust/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ pub(crate) fn opt_to_res<T>(opt: Option<T>) -> Result<T> {
opt.ok_or(J4RsError::RustError("Option was found None while converting to result".to_string()))
}

#[allow(unused)]
pub(crate) fn res_to_opt<T>(res: Result<T>) -> Option<T> {
if res.is_err() {
None
} else {
Some(res.unwrap())
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum J4RsError {
GeneralError(String),
Expand Down
14 changes: 7 additions & 7 deletions rust/src/jfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl JavaFxSupport for Jvm {
instance,
"addEventHandler",
&[
InvocationArg::try_from(event_type_instance)?,
InvocationArg::try_from(j4rs_event_handler)?,
InvocationArg::from(event_type_instance),
InvocationArg::from(j4rs_event_handler),
],
)?;
Ok(btn_action_channel)
Expand All @@ -102,7 +102,7 @@ impl JavaFxSupport for Jvm {
self.invoke(
stage,
"setOnCloseRequest",
&[InvocationArg::try_from(j4rs_event_handler)?],
&[InvocationArg::from(j4rs_event_handler)],
)?;
Ok(action_channel)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ impl JavaFxSupport for Jvm {
let controller = self.invoke_static(
CLASS_J4RS_FXML_LOADER,
"loadFxml",
&[InvocationArg::try_from(cloned)?, InvocationArg::try_from(path_str)?],
&[InvocationArg::from(cloned), InvocationArg::try_from(path_str)?],
)?;
Ok(FxController::new(controller))
}
Expand Down Expand Up @@ -200,7 +200,7 @@ impl FxController {
jvm.invoke(
&self.controller,
"addControllerInitializedCallback",
&[InvocationArg::try_from(channel_support)?],
&[InvocationArg::from(channel_support)],
)?;
instance_receiver
}
Expand All @@ -221,8 +221,8 @@ impl FxController {
"addEventHandler",
&[
InvocationArg::try_from(node_id)?,
InvocationArg::try_from(j4rs_event_handler)?,
InvocationArg::try_from(event_type_instance)?,
InvocationArg::from(j4rs_event_handler),
InvocationArg::from(event_type_instance),
],
)?;
Ok(event_channel)
Expand Down
8 changes: 4 additions & 4 deletions rust/src/jni_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub(crate) fn global_jobject_from_i8(a: &i8, jni_env: *mut JNIEnv) -> errors::Re
jni_env,
cache::get_byte_class()?,
cache::get_byte_constructor_method()?,
tmp as *const i8,
tmp,
);
create_global_ref_from_local_ref(o, jni_env)
}
Expand Down Expand Up @@ -308,7 +308,7 @@ pub(crate) fn global_jobject_from_i16(a: &i16, jni_env: *mut JNIEnv) -> errors::
jni_env,
cache::get_short_class()?,
cache::get_short_constructor_method()?,
tmp as *const i16,
tmp,
);
create_global_ref_from_local_ref(o, jni_env)
}
Expand All @@ -321,7 +321,7 @@ pub(crate) fn global_jobject_from_u16(a: &u16, jni_env: *mut JNIEnv) -> errors::
jni_env,
cache::get_character_class()?,
cache::get_character_constructor_method()?,
tmp as *const u16,
tmp,
);
create_global_ref_from_local_ref(o, jni_env)
}
Expand Down Expand Up @@ -364,7 +364,7 @@ pub(crate) fn global_jobject_from_i32(a: &i32, jni_env: *mut JNIEnv) -> errors::
jni_env,
cache::get_integer_class()?,
cache::get_integer_constructor_method()?,
tmp as *const i32,
tmp,
);
create_global_ref_from_local_ref(o, jni_env)
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub extern "C" fn Java_org_astonbitecode_j4rs_api_invocation_NativeCallbackToRus
let tx = unsafe { Box::from_raw(p) };

let result = tx.send(Ok(instance));
if let Err(_) = result {
if result.is_err() {
panic!("Could not send to the defined callback channel to complete the future");
}
} else {
Expand All @@ -150,7 +150,7 @@ pub unsafe extern "C" fn Java_org_astonbitecode_j4rs_api_invocation_NativeCallba
let tx = unsafe { Box::from_raw(p) };

let result = tx.send(Err(errors::J4RsError::JavaError(st)));
if let Err(_) = result {
if result.is_err() {
panic!("Could not send to the defined callback channel to fail a future");
}
} else {
Expand Down
Loading