drt_sc_scenario/debug_executor/
static_var_stack.rs1use std::{cell::RefCell, rc::Rc};
2
3use drt_sc::types::LockableStaticBuffer;
4
5use super::TxStaticVars;
6
7#[derive(Debug, Default)]
8pub struct StaticVarData {
9 pub lockable_static_buffer_cell: RefCell<LockableStaticBuffer>,
10 pub static_vars_cell: RefCell<TxStaticVars>,
11}
12
13#[derive(Debug, Default)]
14pub struct StaticVarStack(Vec<Rc<StaticVarData>>);
15
16thread_local!(
17 static STATIC_STACK: RefCell<StaticVarStack> = RefCell::new(StaticVarStack::default())
18);
19
20impl StaticVarStack {
21 pub fn static_peek() -> Rc<StaticVarData> {
22 STATIC_STACK.with(|cell| {
23 let stack = cell.borrow();
24 stack.0.last().unwrap().clone()
25 })
26 }
27
28 pub fn static_push() {
29 STATIC_STACK.with(|cell| {
30 let mut stack = cell.borrow_mut();
31 stack.0.push(Rc::default());
32 })
33 }
34
35 pub fn static_pop() -> Rc<StaticVarData> {
36 STATIC_STACK.with(|cell| {
37 let mut stack = cell.borrow_mut();
38 stack.0.pop().unwrap()
39 })
40 }
41}