From fd47f6be3e403d83b04ef42e6824b8786e7446ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 17 Dec 2024 17:50:21 +0100 Subject: [PATCH] fix: deno_resolver crate without 'sync' feature --- resolvers/deno/sync.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/resolvers/deno/sync.rs b/resolvers/deno/sync.rs index 6e6233690192b9..ebcf8509d50d45 100644 --- a/resolvers/deno/sync.rs +++ b/resolvers/deno/sync.rs @@ -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(RefCell>); + #[derive(Debug)] + pub struct MaybeDashMap(RefCell>); + + impl Default for MaybeDashMap + where + K: Eq + Hash, + S: Default + BuildHasher + Clone, + { + fn default() -> Self { + Self(RefCell::new(Default::default())) + } + } - impl MaybeDashMap { - pub fn get(&'a self, key: &K) -> Option<&'a V> { - let inner = self.0.borrow(); - inner.get(key) + impl MaybeDashMap { + pub fn get<'a>(&'a self, key: &K) -> Option> { + Ref::filter_map(self.0.borrow(), |map| map.get(key)).ok() } pub fn insert(&self, key: K, value: V) -> Option { - let inner = self.0.borrow_mut(); + let mut inner = self.0.borrow_mut(); inner.insert(key, value) } }