difftreelog
feat `ContextBuilder`
in: master
Helper for fancier building of user contexts
2 files changed
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth139 }139 }140}140}141142#[derive(Default)]143pub struct ContextBuilder {144 bindings: GcHashMap<IStr, Thunk<Val>>,145}146impl ContextBuilder {147 pub fn new() -> Self {148 Self::default()149 }150 pub fn with_capacity(capacity: usize) -> Self {151 Self {152 bindings: GcHashMap::with_capacity(capacity),153 }154 }155 pub fn bind(&mut self, name: IStr, value: Thunk<Val>) -> &mut Self {156 self.bindings.insert(name, value);157 self158 }159 pub fn build(self) -> Context {160 Context(Cc::new(ContextInternals {161 bindings: LayeredHashMap::new(self.bindings),162 dollar: None,163 sup: None,164 this: None,165 }))166 }167}141168crates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth23 }23 }24 }24 }2526 pub(crate) fn new(layer: GcHashMap<IStr, Thunk<Val>>) -> Self {27 Self(Cc::new(LayeredHashMapInternals {28 parent: None,29 current: layer,30 }))31 }253226 pub fn extend(self, new_layer: GcHashMap<IStr, Thunk<Val>>) -> Self {33 pub fn extend(self, new_layer: GcHashMap<IStr, Thunk<Val>>) -> Self {27 Self(Cc::new(LayeredHashMapInternals {34 Self(Cc::new(LayeredHashMapInternals {