libspecr/map/
mod.rs

1use std::collections::HashSet;
2
3use im::HashMap as IMHashMap;
4
5use crate::*;
6
7mod func;
8mod iter;
9
10#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug, GcCompat)]
11/// Garbage-collected hash map implementing `Copy`.
12pub struct Map<K: Obj, V: Obj>(pub(crate) GcCow<IMHashMap<K, V>>);
13
14impl<K: Obj, V: Obj> GcCompat for IMHashMap<K, V> {
15    fn points_to(&self, m: &mut HashSet<usize>) {
16        for (k, v) in self.iter() {
17            k.points_to(m);
18            v.points_to(m);
19        }
20    }
21}
22
23// This is not #[derive]d, as this would wrongly require K: Default.
24impl<K: Obj, V: Obj> Default for Map<K, V> {
25    fn default() -> Self {
26        Self(Default::default())
27    }
28}