Skip to content

Commit

Permalink
Clippy improvements to rs_port.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Dec 12, 2024
1 parent 5cd005c commit f258548
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
8 changes: 4 additions & 4 deletions source/ports/rs_port/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ where
Box::<[T]>::into_raw(self.iter().cloned().collect()) as *mut ()
}
}
impl<'c> Clone for Box<dyn MetaCallValue + 'c> {
impl Clone for Box<dyn MetaCallValue + '_> {
fn clone(&self) -> Self {
clone_box(&**self)
}
}
impl<'c> Clone for Box<dyn MetaCallValue + Send + 'c> {
impl Clone for Box<dyn MetaCallValue + Send + '_> {
fn clone(&self) -> Self {
clone_box(&**self)
}
}
impl<'c> Clone for Box<dyn MetaCallValue + Sync + 'c> {
impl Clone for Box<dyn MetaCallValue + Sync + '_> {
fn clone(&self) -> Self {
clone_box(&**self)
}
}
impl<'c> Clone for Box<dyn MetaCallValue + Send + Sync + 'c> {
impl Clone for Box<dyn MetaCallValue + Send + Sync + '_> {
fn clone(&self) -> Self {
clone_box(&**self)
}
Expand Down
18 changes: 11 additions & 7 deletions source/ports/rs_port/src/types/metacall_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::MetaCallValue;
use std::{ffi::NulError, path::PathBuf};
use std::{ffi::NulError, fmt, path::PathBuf};

#[derive(Debug, Clone)]
/// This error happens when it's not possible to initialize the MetaCall core. You can check
Expand All @@ -16,9 +16,9 @@ impl Default for MetaCallInitError {
MetaCallInitError::new()
}
}
impl ToString for MetaCallInitError {
fn to_string(&self) -> String {
String::from("Failed to initialize MetaCall!")
impl fmt::Display for MetaCallInitError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Failed to initialize MetaCall")
}
}

Expand All @@ -38,9 +38,13 @@ impl MetaCallStringConversionError {
}
}
}
impl ToString for MetaCallStringConversionError {
fn to_string(&self) -> String {
self.original_string.clone()
impl fmt::Display for MetaCallStringConversionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Failed to convert string: {}",
self.original_string.clone()
)
}
}

Expand Down
31 changes: 15 additions & 16 deletions source/ports/rs_port/src/types/metacall_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ use std::{
sync::Arc,
};

unsafe impl Send for metacall_exception_type {}
unsafe impl Sync for metacall_exception_type {}

/// Represents MetaCall exception. You can create an exception with [new](#method.new).
pub struct MetaCallException {
exception_struct: Arc<metacall_exception_type>,
leak: bool,
value: *mut c_void,
}

unsafe impl Send for MetaCallException {}
unsafe impl Sync for MetaCallException {}

impl Clone for MetaCallException {
fn clone(&self) -> Self {
Self {
Expand All @@ -31,11 +36,7 @@ impl Clone for MetaCallException {
}
impl Debug for MetaCallException {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"MetaCallException {}",
format!("{{ {} }}", self.to_string())
)
write!(f, "MetaCallException: {}", self)
}
}

Expand Down Expand Up @@ -146,11 +147,7 @@ impl Clone for MetaCallThrowable {
}
impl Debug for MetaCallThrowable {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"MetaCallThrowable {}",
format!("{{ {} }}", self.to_string())
)
write!(f, "MetaCallThrowable: {}", self)
}
}

Expand Down Expand Up @@ -205,19 +202,21 @@ impl MetaCallThrowable {
}
}

impl ToString for MetaCallException {
fn to_string(&self) -> String {
format!(
impl fmt::Display for MetaCallException {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"[Exception(code: `{}`)]: {}",
self.get_code(),
self.get_message()
)
}
}
impl ToString for MetaCallThrowable {
fn to_string(&self) -> String {

impl fmt::Display for MetaCallThrowable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let throwable_value = self.get_value_untyped();
format!("[Throwable]: {:#?}", throwable_value)
write!(f, "[Throwable]: {:#?}", throwable_value)
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/ports/rs_port/src/types/metacall_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Clone for MetaCallPointer {
fn clone(&self) -> Self {
Self {
leak: true,
rust_value: self.rust_value.clone(),
rust_value: self.rust_value,
rust_value_leak: true,
value: self.value,
}
Expand Down

0 comments on commit f258548

Please sign in to comment.