use std::sync::Arc;
use std::sync::OnceLock;
use kevy_config::Config;
static GLOBAL: OnceLock<Arc<Config>> = OnceLock::new();
pub fn init(cfg: Arc<Config>) {
let _ = GLOBAL.set(cfg);
}
pub fn get() -> Arc<Config> {
GLOBAL
.get()
.cloned()
.unwrap_or_else(|| Arc::new(Config::default()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn init_sets_once_then_ignores_subsequent_calls() {
let first = Arc::new(Config::default());
init(first.clone());
let second = Arc::new({
let mut c = Config::default();
c.memory.maxmemory = 12345;
c
});
init(second.clone());
let live = get();
assert_eq!(
live.memory.maxmemory, first.memory.maxmemory,
"init must be idempotent — second call should not overwrite"
);
}
#[test]
fn get_after_init_returns_the_installed_config() {
let live = get();
assert!(Arc::strong_count(&live) >= 1);
}
}