From 1da50afba15e7b454d517af7f74eebb734fdbf6b Mon Sep 17 00:00:00 2001 From: Matt Yan Date: Fri, 18 Jul 2025 08:27:25 +0900 Subject: [PATCH] implement ImplicitClone for more types UseStateHandle, UseStateSetter, UseReducerHandle, UseReducerDispatcher --- packages/yew/src/functional/hooks/mod.rs | 1 + packages/yew/src/functional/hooks/use_reducer.rs | 6 ++++++ packages/yew/src/functional/hooks/use_state.rs | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/packages/yew/src/functional/hooks/mod.rs b/packages/yew/src/functional/hooks/mod.rs index 5787cb56c..3795809e9 100644 --- a/packages/yew/src/functional/hooks/mod.rs +++ b/packages/yew/src/functional/hooks/mod.rs @@ -7,6 +7,7 @@ mod use_prepared_state; mod use_reducer; mod use_ref; mod use_state; + mod use_transitive_state; pub use use_callback::*; diff --git a/packages/yew/src/functional/hooks/use_reducer.rs b/packages/yew/src/functional/hooks/use_reducer.rs index 03280f982..153d1f6c7 100644 --- a/packages/yew/src/functional/hooks/use_reducer.rs +++ b/packages/yew/src/functional/hooks/use_reducer.rs @@ -4,6 +4,8 @@ use std::marker::PhantomData; use std::ops::Deref; use std::rc::Rc; +use implicit_clone::ImplicitClone; + use crate::functional::{hook, Hook, HookContext}; use crate::html::IntoPropValue; use crate::Callback; @@ -97,6 +99,8 @@ where } } +impl ImplicitClone for UseReducerHandle where T: Reducible {} + /// Dispatcher handle for [`use_reducer`] and [`use_reducer_eq`] hook pub struct UseReducerDispatcher where @@ -138,6 +142,8 @@ where } } +impl ImplicitClone for UseReducerDispatcher where T: Reducible {} + impl From> for Callback<::Action> where T: Reducible, diff --git a/packages/yew/src/functional/hooks/use_state.rs b/packages/yew/src/functional/hooks/use_state.rs index 441f3a5d9..835e8ab29 100644 --- a/packages/yew/src/functional/hooks/use_state.rs +++ b/packages/yew/src/functional/hooks/use_state.rs @@ -2,6 +2,8 @@ use std::fmt; use std::ops::Deref; use std::rc::Rc; +use implicit_clone::ImplicitClone; + use super::{use_reducer, use_reducer_eq, Reducible, UseReducerDispatcher, UseReducerHandle}; use crate::functional::hook; use crate::html::IntoPropValue; @@ -151,6 +153,8 @@ where } } +impl ImplicitClone for UseStateHandle {} + /// Setter handle for [`use_state`] and [`use_state_eq`] hook pub struct UseStateSetter { inner: UseReducerDispatcher>, @@ -191,6 +195,8 @@ impl PartialEq for UseStateSetter { } } +impl ImplicitClone for UseStateSetter {} + impl UseStateSetter { /// Replaces the value pub fn set(&self, value: T) {