feat(registry): const initialization meaning no necessary lazy_static

This commit is contained in:
Nova
2022-08-17 19:28:52 -04:00
parent 85077146d3
commit c272cfaed1
7 changed files with 17 additions and 28 deletions

View File

@@ -5,11 +5,15 @@ use std::sync::{Arc, Weak};
use core::hash::BuildHasherDefault;
use dashmap::DashMap;
use once_cell::sync::Lazy;
use rustc_hash::FxHasher;
pub struct Registry<T>(DashMap<usize, Weak<T>, BuildHasherDefault<FxHasher>>);
pub struct Registry<T>(Lazy<DashMap<usize, Weak<T>, BuildHasherDefault<FxHasher>>>);
impl<T> Registry<T> {
pub const fn new() -> Self {
Registry(Lazy::new(|| DashMap::default()))
}
pub fn add(&self, t: T) -> Arc<T> {
let t_arc = Arc::new(t);
self.add_raw(&t_arc);
@@ -32,9 +36,3 @@ impl<T> Registry<T> {
self.0.clear();
}
}
impl<T> Default for Registry<T> {
fn default() -> Self {
Registry(DashMap::default())
}
}