generics.rs 1.8 KB

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