From 87c0b7ec38a98610fcd4459df36b174cef27f1a6 Mon Sep 17 00:00:00 2001 From: Taylor Holliday Date: Sun, 10 Dec 2023 21:00:08 -0800 Subject: [PATCH] #53 Add with_state --- src/context.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/context.rs b/src/context.rs index ba7c02f..b869664 100644 --- a/src/context.rs +++ b/src/context.rs @@ -136,12 +136,17 @@ pub struct Context { thread_local! { pub(crate) static CONTEXT: RefCell = RefCell::new(Context::new()); + pub(crate) static STATE_MAP: RefCell = RefCell::new(StateMap::new()); } pub(crate) fn with_context(id: ContextId, f: impl FnOnce(&mut Context) -> T) -> T { CONTEXT.with(|cx| f(&mut cx.borrow_mut())) } +pub(crate) fn with_state(f: impl FnOnce(&mut StateMap) -> T) -> T { + STATE_MAP.with(|map| f(&mut map.borrow_mut())) +} + impl Default for Context { fn default() -> Self { Self::new()