use std::{
rc::Rc,
time::{SystemTime, UNIX_EPOCH},
};
struct SystemRuntimeProviders;
impl RuntimeProviders for SystemRuntimeProviders {}
pub trait RuntimeProviders {
fn random(&self) -> f64 {
rand::random()
}
fn now_millis(&self) -> i64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as i64
}
fn debug(&self, message: &str) {
eprintln!("{message}");
}
}
std::thread_local! {
static DEFAULT_RUNTIME_PROVIDERS: Rc<dyn RuntimeProviders> = Rc::new(SystemRuntimeProviders);
}
pub fn default_runtime_providers() -> Rc<dyn RuntimeProviders> {
DEFAULT_RUNTIME_PROVIDERS.with(Clone::clone)
}