1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Common types and trait bounds used throughout dioxus-provider
//!
//! This module defines the foundational trait bounds that enable dioxus-provider to work
//! seamlessly across different platforms (web, desktop, mobile) while maintaining type safety.
/// Common trait bounds for provider parameters
///
/// Provider parameters must satisfy these bounds to enable:
/// - **Clone**: Parameters are cloned when passed to async functions and stored in cache keys
/// - **PartialEq**: Required for comparing parameters to determine cache key equality
/// - **Hash**: Enables efficient cache key generation from parameter values
/// - **Debug**: Provides better error messages and logging output
/// - **Send + Sync**: Allows parameters to be safely shared across async contexts
/// - **'static**: Ensures parameters can be stored in global caches and async tasks
///
/// ## Example
///
/// ```rust
/// // Simple types automatically satisfy these bounds:
/// use dioxus_provider::prelude::*;
///
/// #[provider]
/// async fn fetch_user(user_id: u32) -> Result<String, String> {
/// // u32 implements ProviderParamBounds automatically
/// Ok(format!("User {}", user_id))
/// }
///
/// // Custom types need to derive the necessary traits:
/// #[derive(Clone, PartialEq, Eq, Hash, Debug)]
/// struct UserId(u32);
///
/// #[provider]
/// async fn fetch_user_custom(id: UserId) -> Result<String, String> {
/// // UserId now implements ProviderParamBounds
/// Ok(format!("User {}", id.0))
/// }
/// ```
/// Common trait bounds for provider output types
///
/// Provider outputs must satisfy these bounds to enable:
/// - **Clone**: Results are cloned when cached and served to multiple components
/// - **PartialEq**: Allows change detection to avoid unnecessary re-renders
/// - **Send + Sync**: Enables safe sharing of results across async contexts
/// - **'static**: Required for storing results in global caches and signals
///
/// ## Example
///
/// ```rust
/// use dioxus_provider::prelude::*;
///
/// // Simple types work out of the box:
/// #[provider]
/// async fn fetch_count() -> Result<i32, String> {
/// Ok(42)
/// }
///
/// // Custom types need to derive Clone and PartialEq:
/// #[derive(Clone, PartialEq)]
/// struct User {
/// id: u32,
/// name: String,
/// }
///
/// #[provider]
/// async fn fetch_user(id: u32) -> Result<User, String> {
/// Ok(User { id, name: "Alice".to_string() })
/// }
/// ```
/// Common trait bounds for provider error types
///
/// Provider errors must satisfy these bounds to enable:
/// - **Clone**: Errors are cloned when cached and displayed to users
/// - **PartialEq**: Enables error comparison and change detection
/// - **Send + Sync**: Allows safe propagation of errors across async boundaries
/// - **'static**: Required for storing errors in caches and error states
///
/// ## Example
///
/// ```rust
/// use dioxus_provider::prelude::*;
/// use thiserror::Error;
///
/// // String works as a simple error type:
/// #[provider]
/// async fn simple_provider() -> Result<String, String> {
/// Err("Something went wrong".to_string())
/// }
///
/// // Custom error types provide better structure:
/// #[derive(Error, Debug, Clone, PartialEq)]
/// pub enum MyError {
/// #[error("Network error: {0}")]
/// Network(String),
/// #[error("Not found")]
/// NotFound,
/// }
///
/// #[provider]
/// async fn typed_provider() -> Result<String, MyError> {
/// Err(MyError::NotFound)
/// }
/// ```