git.delta.rocks / jrsonnet / refs/commits / 31f2b649c192

difftreelog

source

crates/jrsonnet-evaluator/src/dynamic.rs632 Bsourcehistory
1use jrsonnet_gc::{Gc, GcCell, Trace};23#[derive(Clone, Trace)]4#[trivially_drop]5pub struct FutureWrapper<V: Trace + 'static>(pub Gc<GcCell<Option<V>>>);6impl<T: Trace + 'static> FutureWrapper<T> {7	pub fn new() -> Self {8		Self(Gc::new(GcCell::new(None)))9	}10	pub fn fill(self, value: T) {11		assert!(self.0.borrow().is_none(), "wrapper is filled already");12		self.0.borrow_mut().replace(value);13	}14}15impl<T: Clone + Trace + 'static> FutureWrapper<T> {16	pub fn unwrap(&self) -> T {17		self.0.borrow().as_ref().cloned().unwrap()18	}19}2021impl<T: Trace + 'static> Default for FutureWrapper<T> {22	fn default() -> Self {23		Self::new()24	}25}