use std::sync::OnceLock; use crate::{Program, ProgramCollect}; /// Global static reference to the current program instance pub(crate) static THIS_PROGRAM: OnceLock>> = OnceLock::new(); /// Returns a reference to the current program instance, panics if not set. pub fn this() -> &'static Program where C: ProgramCollect + 'static, { try_get_this_program().expect("Program not initialized") } /// Returns a reference to the current program instance, if set. fn try_get_this_program() -> Option<&'static Program> where C: ProgramCollect + 'static, { THIS_PROGRAM.get()?.as_ref()?.downcast_ref::>() }