cultcache-rs: the mark scope closes on drop; scopes never nest

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-12 03:10:22 +00:00
commit 4872091a7f

View file

@ -897,12 +897,14 @@ impl<'de> serde::Deserialize<'de> for __UnitArmSlots {
}
}
/// Puts the previous scope back whatever the decode did.
struct UnreadScope(Option<MarkScope>);
/// 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<UnreadSlots> {
@ -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);
}
}