Adjust impl for signal syntax to allow cloned values

This commit is contained in:
Jonathan Kelley 2024-01-15 21:43:30 -08:00
parent 33bba24867
commit d88561f973
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
2 changed files with 6 additions and 3 deletions

View file

@ -14,7 +14,7 @@ fn app() -> Element {
// Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps
use_future(|| async move {
loop {
if running.cloned() {
if running() {
count += 1;
}
tokio::time::sleep(Duration::from_millis(400)).await;

View file

@ -348,7 +348,10 @@ impl<T: 'static> PartialEq for Signal<T> {
}
}
impl<T: Copy> Deref for Signal<T> {
/// Allow calling a signal with signal() syntax
///
/// Currently only limited to copy types, though could probably specialize for string/arc/rc
impl<T: Copy + Clone> Deref for Signal<T> {
type Target = dyn Fn() -> T;
fn deref(&self) -> &Self::Target {
@ -486,7 +489,7 @@ impl<T: 'static> PartialEq for ReadOnlySignal<T> {
}
}
impl<T: Copy> Deref for ReadOnlySignal<T> {
impl<T: Copy + Clone> Deref for ReadOnlySignal<T> {
type Target = dyn Fn() -> T;
fn deref(&self) -> &Self::Target {