pub trait IntoProviderParam {
type Param: Clone + PartialEq + Hash + Debug + Send + Sync + 'static;
// Required method
fn into_param(self) -> Self::Param;
}Expand description
Trait for normalizing different parameter formats to work with providers
This trait allows the use_provider hook to accept parameters in different formats:
()for no parameters(param,)for single parameter in tuple (e.g.,(42,))- Common primitive types directly (e.g.,
42,"foo".to_string()) - Custom types that implement the required bounds directly
§Custom Parameter Types
Custom types can be used directly as provider parameters by implementing the required bounds:
Clone + PartialEq + Hash + Debug + Send + Sync + 'static
Use the provider_param! macro for convenience:
use dioxus_provider::{prelude::*, provider_param};
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct UserId(u32);
provider_param!(UserId); // Enable direct usage
#[provider]
async fn fetch_user(user_id: UserId) -> Result<User, String> { ... }
// Now you can use it directly:
let user = use_provider(fetch_user(), UserId(42));§Usage and Ambiguity
- If your provider expects a single parameter, you can pass it directly or as a single-element tuple.
- Note: Tuple syntax
(param,)has priority over direct parameter syntax for types that implement both. - For string parameters, both
Stringand&strare supported directly.
§Examples
use dioxus_provider::prelude::*;
#[provider]
async fn fetch_user(user_id: u32) -> Result<User, String> { ... }
// All of these are valid:
let user = use_provider(fetch_user(), 42); // direct primitive
let user = use_provider(fetch_user(), (42,)); // single-element tuple
let user = use_provider(fetch_user(), "foo".to_string()); // StringRequired Associated Types§
Required Methods§
Sourcefn into_param(self) -> Self::Param
fn into_param(self) -> Self::Param
Convert the input into the parameter format expected by the provider