IntoProviderParam

Trait IntoProviderParam 

Source
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 String and &str are 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()); // String

Required Associated Types§

Source

type Param: Clone + PartialEq + Hash + Debug + Send + Sync + 'static

The target parameter type after conversion

Required Methods§

Source

fn into_param(self) -> Self::Param

Convert the input into the parameter format expected by the provider

Implementations on Foreign Types§

Source§

impl IntoProviderParam for ()

Source§

type Param = ()

Source§

fn into_param(self) -> Self::Param

Source§

impl<T> IntoProviderParam for (T,)
where T: Clone + PartialEq + Hash + Debug + Send + Sync + 'static,

Source§

type Param = T

Source§

fn into_param(self) -> Self::Param

Implementors§

Source§

impl<T> IntoProviderParam for T
where T: Clone + PartialEq + Hash + Debug + Send + Sync + 'static + DirectParam,

Source§

type Param = T