git.delta.rocks / jrsonnet / refs/commits / 3ee61c42d34d

difftreelog

source

crates/jrsonnet-evaluator/src/dynamic.rs788 Bsourcehistory
1use std::cell::RefCell;23use jrsonnet_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	pub fn new_filled(v: T) -> Self {12		Self(Cc::new(RefCell::new(Some(v))))13	}14	/// # Panics15	/// If wrapper is filled already16	pub fn fill(self, value: T) {17		assert!(self.0.borrow().is_none(), "wrapper is filled already");18		self.0.borrow_mut().replace(value);19	}20}21impl<T: Clone + Trace + 'static> Pending<T> {22	/// # Panics23	/// If wrapper is not yet filled24	pub fn unwrap(&self) -> T {25		self.0.borrow().as_ref().cloned().unwrap()26	}27}2829impl<T: Trace + 'static> Default for Pending<T> {30	fn default() -> Self {31		Self::new()32	}33}