git.delta.rocks / jrsonnet / refs/commits / 32f6ee5b9541

difftreelog

source

crates/jrsonnet-evaluator/src/dynamic.rs702 Bsourcehistory
1use std::cell::RefCell;23use gcmodule::{Cc, Trace};45#[derive(Clone, Trace)]6pub struct Pending<V: Trace + 'static>(pub Cc<RefCell<Option<V>>>);7impl<T: Trace + 'static> Pending<T> {8	pub fn new() -> Self {9		Self(Cc::new(RefCell::new(None)))10	}11	/// # Panics12	/// If wrapper is filled already13	pub fn fill(self, value: T) {14		assert!(self.0.borrow().is_none(), "wrapper is filled already");15		self.0.borrow_mut().replace(value);16	}17}18impl<T: Clone + Trace + 'static> Pending<T> {19	/// # Panics20	/// If wrapper is not yet filled21	pub fn unwrap(&self) -> T {22		self.0.borrow().as_ref().cloned().unwrap()23	}24}2526impl<T: Trace + 'static> Default for Pending<T> {27	fn default() -> Self {28		Self::new()29	}30}