Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deno_resolver crate without 'sync' feature #27403

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions resolvers/deno/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 MaybeDashMap<K, V, S> {
pub fn get(&'a self, key: &K) -> Option<&'a V> {
let inner = self.0.borrow();
inner.get(key)
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)
}
}
Expand Down
Loading