1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-18 13:22:55 -05:00

fix: deno_resolver crate without 'sync' feature (#27403)

This commit is contained in:
Bartek Iwańczuk 2024-12-17 17:36:32 +00:00 committed by GitHub
parent ee9f24cdcd
commit d632ec9e70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,21 +13,35 @@ mod inner {
#[cfg(not(feature = "sync"))]
mod inner {
use std::cell::Ref;
use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::BuildHasher;
use std::hash::Hash;
use std::hash::RandomState;
pub use std::rc::Rc as MaybeArc;
// Wrapper struct that exposes a subset of `DashMap` API.
#[derive(Default)]
struct MaybeDashMap<K, V, S = RandomState>(RefCell<HashMap<K, V, S>>);
#[derive(Debug)]
pub struct MaybeDashMap<K, V, S = RandomState>(RefCell<HashMap<K, V, S>>);
impl MaybeDashMap<K, V, S> {
pub fn get(&'a self, key: &K) -> Option<&'a V> {
let inner = self.0.borrow();
inner.get(key)
impl<K, V, S> Default for MaybeDashMap<K, V, S>
where
K: Eq + Hash,
S: Default + BuildHasher + Clone,
{
fn default() -> Self {
Self(RefCell::new(Default::default()))
}
}
impl<K: Eq + Hash, V, S: BuildHasher> MaybeDashMap<K, V, S> {
pub fn get<'a>(&'a self, key: &K) -> Option<Ref<'a, V>> {
Ref::filter_map(self.0.borrow(), |map| map.get(key)).ok()
}
pub fn insert(&self, key: K, value: V) -> Option<V> {
let inner = self.0.borrow_mut();
let mut inner = self.0.borrow_mut();
inner.insert(key, value)
}
}