From 4872091a7f30b7bf9ded8e60ab0c2078002dd9ee Mon Sep 17 00:00:00 2001 From: Libby Date: Thu, 12 Nov 2026 03:10:22 +0000 Subject: [PATCH] cultcache-rs: the mark scope closes on drop; scopes never nest Co-Authored-By: Claude Sonnet 5.5 --- packages/cultcache-rs/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/cultcache-rs/src/lib.rs b/packages/cultcache-rs/src/lib.rs index 942f4e05..5a782221 100644 --- a/packages/cultcache-rs/src/lib.rs +++ b/packages/cultcache-rs/src/lib.rs @@ -897,12 +897,14 @@ impl<'de> serde::Deserialize<'de> for __UnitArmSlots { } } -/// Puts the previous scope back whatever the decode did. -struct UnreadScope(Option); +/// The scope one marked decode opens on this thread; closed when it ends, whatever the decode did. A marked decode is +/// never re-entered (only the cache's own checks open one), so scopes do not nest. +struct UnreadScope; impl UnreadScope { fn open() -> Self { - Self(UNREAD_SLOTS.with(|scope| scope.replace(Some(MarkScope::default())))) + UNREAD_SLOTS.with(|scope| *scope.borrow_mut() = Some(MarkScope::default())); + Self } fn mark(&self) -> Option { @@ -912,7 +914,7 @@ impl UnreadScope { impl Drop for UnreadScope { fn drop(&mut self) { - UNREAD_SLOTS.with(|scope| *scope.borrow_mut() = self.0.take()); + UNREAD_SLOTS.with(|scope| *scope.borrow_mut() = None); } }