diff --git a/source/ports/rs_port/src/helpers.rs b/source/ports/rs_port/src/helpers.rs index 8dc754416..69cfb132c 100644 --- a/source/ports/rs_port/src/helpers.rs +++ b/source/ports/rs_port/src/helpers.rs @@ -89,22 +89,22 @@ where Box::<[T]>::into_raw(self.iter().cloned().collect()) as *mut () } } -impl<'c> Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { clone_box(&**self) } } -impl<'c> Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { clone_box(&**self) } } -impl<'c> Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { clone_box(&**self) } } -impl<'c> Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { clone_box(&**self) } diff --git a/source/ports/rs_port/src/types/metacall_error.rs b/source/ports/rs_port/src/types/metacall_error.rs index 51b5e6006..7c3e85484 100644 --- a/source/ports/rs_port/src/types/metacall_error.rs +++ b/source/ports/rs_port/src/types/metacall_error.rs @@ -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 @@ -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") } } @@ -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() + ) } } diff --git a/source/ports/rs_port/src/types/metacall_exception.rs b/source/ports/rs_port/src/types/metacall_exception.rs index 67a34e15a..56905d9e5 100644 --- a/source/ports/rs_port/src/types/metacall_exception.rs +++ b/source/ports/rs_port/src/types/metacall_exception.rs @@ -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, 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 { @@ -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) } } @@ -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) } } @@ -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) } } diff --git a/source/ports/rs_port/src/types/metacall_pointer.rs b/source/ports/rs_port/src/types/metacall_pointer.rs index 802aa153a..55ccc6386 100644 --- a/source/ports/rs_port/src/types/metacall_pointer.rs +++ b/source/ports/rs_port/src/types/metacall_pointer.rs @@ -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, }