fibre_cache 0.4.8

Best in-class comprehensive, most flexible, high-performance, concurrent multi-mode sync/async caching library for Rust. It provides a rich, ergonomic API including a runtime-agnostic CacheLoader, an atomic `entry` API, and a wide choice of modern cache policies like W-TinyLFU, SIEVE, ARC, LRU, Clock, SLRU, Random.
Documentation
use std::{future::Future, pin::Pin};

/// A trait for spawning a future onto an asynchronous runtime.
pub trait TaskSpawner: Send + Sync + 'static {
  /// Spawns a type-erased future.
  fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
}

#[cfg(feature = "tokio")]
pub struct TokioSpawner(tokio::runtime::Handle);

#[cfg(feature = "tokio")]
impl TokioSpawner {
  /// Creates a spawner that uses the current Tokio runtime context.
  /// Panics if called outside of a Tokio runtime.
  pub fn new() -> Self {
    Self(tokio::runtime::Handle::current())
  }
}

#[cfg(feature = "tokio")]
impl TaskSpawner for TokioSpawner {
  fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>)
  {
    self.0.spawn(future);
  }
}