generics.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. use dioxus::prelude::*;
  2. // This test just checks that props compile with generics
  3. // It will not actually run any code
  4. #[test]
  5. #[allow(unused)]
  6. #[allow(non_snake_case)]
  7. fn generic_props_compile() {
  8. fn app() -> Element {
  9. rsx! {
  10. TakesClone {
  11. value: "hello world"
  12. }
  13. TakesCloneManual {
  14. value: "hello world"
  15. }
  16. TakesCloneManualWhere {
  17. value: "hello world"
  18. }
  19. }
  20. }
  21. #[component]
  22. fn TakesClone<T: Clone + PartialEq + 'static>(value: T) -> Element {
  23. rsx! {}
  24. }
  25. #[derive(Props, Clone, PartialEq)]
  26. struct TakesCloneManualProps<T: Clone + PartialEq + 'static> {
  27. value: T,
  28. }
  29. fn TakesCloneManual<T: Clone + PartialEq>(props: TakesCloneManualProps<T>) -> Element {
  30. rsx! {}
  31. }
  32. #[derive(Props, Clone, PartialEq)]
  33. struct TakesCloneManualWhereProps<T>
  34. where
  35. T: Clone + PartialEq + 'static,
  36. {
  37. value: T,
  38. }
  39. fn TakesCloneManualWhere<T: Clone + PartialEq>(
  40. props: TakesCloneManualWhereProps<T>,
  41. ) -> Element {
  42. rsx! {}
  43. }
  44. #[derive(Props, Clone, PartialEq)]
  45. struct TakesCloneManualWhereWithOwnerProps<T>
  46. where
  47. T: Clone + PartialEq + 'static,
  48. {
  49. value: EventHandler<T>,
  50. }
  51. fn TakesCloneManualWhereWithOwner<T: Clone + PartialEq>(
  52. props: TakesCloneManualWhereWithOwnerProps<T>,
  53. ) -> Element {
  54. rsx! {}
  55. }
  56. }