From dc1ba24470910f960635234ed3bf8a513575a7d7 Mon Sep 17 00:00:00 2001 From: Lukas Potthast Date: Thu, 14 Sep 2023 01:59:23 +0200 Subject: [PATCH] fix: manual Clone and Debug impl for Callbacks (#1703) --- leptos_dom/src/callback.rs | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/leptos_dom/src/callback.rs b/leptos_dom/src/callback.rs index 705f0d7aa7..ea66f58fb8 100644 --- a/leptos_dom/src/callback.rs +++ b/leptos_dom/src/callback.rs @@ -64,7 +64,7 @@ use crate::{AnyElement, ElementDescriptor, HtmlElement, IntoView, View}; use leptos_reactive::StoredValue; -use std::{rc::Rc, sync::Arc}; +use std::{fmt, rc::Rc, sync::Arc}; /// A wrapper trait for calling callbacks. pub trait Callable { @@ -100,9 +100,20 @@ pub trait Callable { /// # Cloning /// See [StoredCallback] -#[derive(Clone)] pub struct Callback(Rc Out>); +impl fmt::Debug for Callback { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt.write_str("Callback") + } +} + +impl Clone for Callback { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + impl Callback { /// creates a new callback from the function or closure pub fn new(f: F) -> Callback @@ -167,9 +178,20 @@ where } /// a callback type that is `Send` and `Sync` if the input type is -#[derive(Clone)] pub struct SyncCallback(Arc Out>); +impl fmt::Debug for SyncCallback { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt.write_str("SyncCallback") + } +} + +impl Clone for SyncCallback { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + impl SyncCallback { /// creates a new callback from the function or closure pub fn new(fun: F) -> Self @@ -216,9 +238,20 @@ impl SyncCallback { /// {render_number} /// /// } -#[derive(Clone)] pub struct HtmlCallback(Rc HtmlElement>); +impl fmt::Debug for HtmlCallback { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt.write_str("HtmlCallback") + } +} + +impl Clone for HtmlCallback { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + impl HtmlCallback { /// creates a new callback from the function or closure pub fn new(f: F) -> Self @@ -286,12 +319,23 @@ impl IntoView for HtmlCallback<()> { /// {render_number} /// /// } -#[derive(Clone)] pub struct ViewCallback(Rc View>); +impl fmt::Debug for ViewCallback { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt.write_str("ViewCallback") + } +} + +impl Clone for ViewCallback { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + impl ViewCallback { /// creates a new callback from the function or closure - fn new(f: F) -> Self + pub fn new(f: F) -> Self where F: Fn(In) -> V + 'static, V: IntoView + 'static,