mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
implement ImplicitClone for more types (#3878)
UseStateHandle, UseStateSetter, UseReducerHandle, UseReducerDispatcher
This commit is contained in:
parent
f0b182d391
commit
607a6cc4b2
@ -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::*;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user