Skip to content

Commit 87c0b7e

Browse files
committed
#53 Add with_state
1 parent 18985bc commit 87c0b7e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ pub struct Context {
136136

137137
thread_local! {
138138
pub(crate) static CONTEXT: RefCell<Context> = RefCell::new(Context::new());
139+
pub(crate) static STATE_MAP: RefCell<StateMap> = RefCell::new(StateMap::new());
139140
}
140141

141142
pub(crate) fn with_context<T>(id: ContextId, f: impl FnOnce(&mut Context) -> T) -> T {
142143
CONTEXT.with(|cx| f(&mut cx.borrow_mut()))
143144
}
144145

146+
pub(crate) fn with_state<T>(f: impl FnOnce(&mut StateMap) -> T) -> T {
147+
STATE_MAP.with(|map| f(&mut map.borrow_mut()))
148+
}
149+
145150
impl Default for Context {
146151
fn default() -> Self {
147152
Self::new()

0 commit comments

Comments
 (0)