Skip to main content

CacheableFn

Trait CacheableFn 

Source
pub trait CacheableFn<Args>: 'static {
    type Output;
    type Future: Future<Output = Result<Self::Output>> + 'static;

    // Required method
    fn call_with(&self, args: Args) -> Self::Future;
}
Expand description

A server function (or any async fn returning dioxus::Result) that can be passed by name to use_cached and invalidate_cached.

Implemented for functions of up to eight arguments. Args is the arguments as a tuple, which Rust infers from the function:

ⓘ
async fn get_bookmarks() -> dioxus::Result<Vec<Media>>;          // Args = ()
async fn get_media(id: String) -> dioxus::Result<Media>;          // Args = (String,)
async fn get_reviews(id: String, page: u32) -> dioxus::Result<_>; // Args = (String, u32)

Only pass function items. A closure compiles, but panics on first use: its type name cannot tell two different reads apart.

Required Associated Types§

Source

type Output

The Ok value.

Source

type Future: Future<Output = Result<Self::Output>> + 'static

The future the function returns.

Required Methods§

Source

fn call_with(&self, args: Args) -> Self::Future

Calls the function with its arguments as a tuple.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, Fut, T, A, B, C, D, E, G, H, I> CacheableFn<(A, B, C, D, E, G, H, I)> for F
where F: Fn(A, B, C, D, E, G, H, I) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B, C, D, E, G, H> CacheableFn<(A, B, C, D, E, G, H)> for F
where F: Fn(A, B, C, D, E, G, H) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B, C, D, E, G> CacheableFn<(A, B, C, D, E, G)> for F
where F: Fn(A, B, C, D, E, G) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B, C, D, E> CacheableFn<(A, B, C, D, E)> for F
where F: Fn(A, B, C, D, E) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B, C, D> CacheableFn<(A, B, C, D)> for F
where F: Fn(A, B, C, D) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B, C> CacheableFn<(A, B, C)> for F
where F: Fn(A, B, C) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A, B> CacheableFn<(A, B)> for F
where F: Fn(A, B) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T, A> CacheableFn<(A,)> for F
where F: Fn(A) -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut

Source§

impl<F, Fut, T> CacheableFn<()> for F
where F: Fn() -> Fut + 'static, Fut: Future<Output = Result<T>> + 'static,

Source§

type Output = T

Source§

type Future = Fut