Skip to main content

Loader

Trait Loader 

Source
pub trait Loader<K, V>: Send + Sync {
    // Required method
    fn load(
        &self,
        key: &K,
    ) -> impl Future<Output = CacheResult<Option<V>>> + Send;
}
Expand description

Single-key data loader abstraction.

Design notes:

  • This trait is intentionally async because loader implementations are usually IO-bound (DB/HTTP/RPC).
  • Methods return impl Future + Send to make the async contract explicit without lint suppression.
  • Returning Option<V> allows negative caching semantics: Ok(None) means “query succeeded but row not found”.

Required Methods§

Source

fn load(&self, key: &K) -> impl Future<Output = CacheResult<Option<V>>> + Send

Loads one key from the source-of-truth backend.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K, V> Loader<K, V> for NoopLoader
where K: Sync,

Source§

impl<K, V, F, Fut> Loader<K, V> for FnLoader<K, V, F, Fut>
where K: Clone + Eq + Hash + Send + Sync + 'static, V: Clone + Send + Sync + 'static, F: Fn(K) -> Fut + Send + Sync + 'static, Fut: Future<Output = CacheResult<Option<V>>> + Send + 'static,