#[macro_export] macro_rules! tl_cache { ($ty:ty : $expr:expr) => {{ thread_local! { static V: $ty = $expr; } V.with(|v| v.clone()) }}; (async $ty:ty : $expr:expr) => {{ type CellType = std::cell::OnceCell<$ty>; thread_local! { static V: CellType = std::cell::OnceCell::default(); } match V.with(|cell: &CellType| cell.get().cloned()) { Some(val) => val as $ty, None => { let val = $expr; let _ = V.with(|cell: &CellType| cell.set(val.clone())); val as $ty }, } }}; }