git.delta.rocks / jrsonnet / refs/commits / df9bc99da41f

difftreelog

source

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