1use jrsonnet_gc::{Gc, Trace};2use jrsonnet_interner::IStr;3use rustc_hash::FxHashMap;45use crate::LazyVal;67#[derive(Trace)]8#[trivially_drop]9pub struct LayeredHashMapInternals {10 parent: Option<LayeredHashMap>,11 current: FxHashMap<IStr, LazyVal>,12}1314#[derive(Trace)]15#[trivially_drop]16pub struct LayeredHashMap(Gc<LayeredHashMapInternals>);1718impl LayeredHashMap {19 pub fn extend(self, new_layer: FxHashMap<IStr, LazyVal>) -> Self {20 Self(Gc::new(LayeredHashMapInternals {21 parent: Some(self),22 current: new_layer,23 }))24 }2526 pub fn get(&self, key: &IStr) -> Option<&LazyVal> {27 (self.0)28 .current29 .get(key)30 .or_else(|| self.0.parent.as_ref().and_then(|p| p.get(key)))31 }32}3334impl Clone for LayeredHashMap {35 fn clone(&self) -> Self {36 Self(self.0.clone())37 }38}3940impl Default for LayeredHashMap {41 fn default() -> Self {42 Self(Gc::new(LayeredHashMapInternals {43 parent: None,44 current: FxHashMap::default(),45 }))46 }47}