implement ImplicitClone for more types (#3878)

UseStateHandle, UseStateSetter, UseReducerHandle, UseReducerDispatcher
This commit is contained in:
Siyuan Yan 2025-07-24 13:58:31 +09:00 committed by GitHub
parent f0b182d391
commit 607a6cc4b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -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::*;

View File

@ -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<T> ImplicitClone for UseReducerHandle<T> where T: Reducible {}
/// Dispatcher handle for [`use_reducer`] and [`use_reducer_eq`] hook
pub struct UseReducerDispatcher<T>
where
@ -138,6 +142,8 @@ where
}
}
impl<T> ImplicitClone for UseReducerDispatcher<T> where T: Reducible {}
impl<T> From<UseReducerDispatcher<T>> for Callback<<T as Reducible>::Action>
where
T: Reducible,

View File

@ -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<T> ImplicitClone for UseStateHandle<T> {}
/// Setter handle for [`use_state`] and [`use_state_eq`] hook
pub struct UseStateSetter<T> {
inner: UseReducerDispatcher<UseStateReducer<T>>,
@ -191,6 +195,8 @@ impl<T> PartialEq for UseStateSetter<T> {
}
}
impl<T> ImplicitClone for UseStateSetter<T> {}
impl<T> UseStateSetter<T> {
/// Replaces the value
pub fn set(&self, value: T) {