Skip to content

Commit 607a6cc

Browse files
implement ImplicitClone for more types (#3878)
UseStateHandle, UseStateSetter, UseReducerHandle, UseReducerDispatcher
1 parent f0b182d commit 607a6cc

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

packages/yew/src/functional/hooks/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod use_prepared_state;
77
mod use_reducer;
88
mod use_ref;
99
mod use_state;
10+
1011
mod use_transitive_state;
1112

1213
pub use use_callback::*;

packages/yew/src/functional/hooks/use_reducer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::marker::PhantomData;
44
use std::ops::Deref;
55
use std::rc::Rc;
66

7+
use implicit_clone::ImplicitClone;
8+
79
use crate::functional::{hook, Hook, HookContext};
810
use crate::html::IntoPropValue;
911
use crate::Callback;
@@ -97,6 +99,8 @@ where
9799
}
98100
}
99101

102+
impl<T> ImplicitClone for UseReducerHandle<T> where T: Reducible {}
103+
100104
/// Dispatcher handle for [`use_reducer`] and [`use_reducer_eq`] hook
101105
pub struct UseReducerDispatcher<T>
102106
where
@@ -138,6 +142,8 @@ where
138142
}
139143
}
140144

145+
impl<T> ImplicitClone for UseReducerDispatcher<T> where T: Reducible {}
146+
141147
impl<T> From<UseReducerDispatcher<T>> for Callback<<T as Reducible>::Action>
142148
where
143149
T: Reducible,

packages/yew/src/functional/hooks/use_state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::fmt;
22
use std::ops::Deref;
33
use std::rc::Rc;
44

5+
use implicit_clone::ImplicitClone;
6+
57
use super::{use_reducer, use_reducer_eq, Reducible, UseReducerDispatcher, UseReducerHandle};
68
use crate::functional::hook;
79
use crate::html::IntoPropValue;
@@ -151,6 +153,8 @@ where
151153
}
152154
}
153155

156+
impl<T> ImplicitClone for UseStateHandle<T> {}
157+
154158
/// Setter handle for [`use_state`] and [`use_state_eq`] hook
155159
pub struct UseStateSetter<T> {
156160
inner: UseReducerDispatcher<UseStateReducer<T>>,
@@ -191,6 +195,8 @@ impl<T> PartialEq for UseStateSetter<T> {
191195
}
192196
}
193197

198+
impl<T> ImplicitClone for UseStateSetter<T> {}
199+
194200
impl<T> UseStateSetter<T> {
195201
/// Replaces the value
196202
pub fn set(&self, value: T) {

0 commit comments

Comments
 (0)