Fix too restrictive Clone bounds in props with generics (#5451)

* Manually implement Clone for *WithOwner for less restrictive bounds.

* add tests

* fix clippy

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
Gabriël KonatandEvan Almloff authored and GitHub committed 2026-04-06 13:18:10 -05:00
1 parent d027e26046
commit a07b406699
2 files changed
+45 -2

No files matched your search

+36 -1
View File
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, marker::PhantomData};
use dioxus::prelude::*;
@@ -104,4 +104,39 @@ fn generic_props_compile() {
p { "{value}" }
}
}
#[derive(Props)]
struct PropsWithOwnerOnlyRequiresStatic<T: 'static> {
value: PhantomData<T>,
trigger_owner: EventHandler<()>,
}
impl<T> PartialEq for PropsWithOwnerOnlyRequiresStatic<T> {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl<T> Clone for PropsWithOwnerOnlyRequiresStatic<T> {
fn clone(&self) -> Self {
PropsWithOwnerOnlyRequiresStatic {
value: PhantomData,
trigger_owner: self.trigger_owner,
}
}
}
fn ReadSignalNoCloneWithOwner<T>(props: PropsWithOwnerOnlyRequiresStatic<T>) -> Element {
rsx! {}
}
#[component]
fn ReadSignalNoClone<T>(value: ReadSignal<T>) -> Element
where
T: PartialEq + Display + 'static,
{
rsx! {
p { "{value}" }
}
}
}