use std::collections::HashMap;
use std::sync::Arc;
use crate::value::ContextValue;
pub(crate) struct ScopeNode {
pub(crate) name: Option<String>,
pub(crate) values: HashMap<&'static str, Arc<dyn ContextValue>>,
pub(crate) parent: Option<Arc<ScopeNode>>,
pub(crate) depth: usize,
pub(crate) remote_chain: Arc<Vec<String>>,
pub(crate) remote_chain_base_depth: usize,
pub(crate) saved_scope_barrier: Option<usize>,
}
pub(crate) struct ScopeGarbage {
pub(crate) _old_values: HashMap<&'static str, Arc<dyn ContextValue>>,
}
pub struct ScopeGuard {
expected_depth: usize,
is_async: bool,
_not_send: std::marker::PhantomData<*const ()>,
}
impl ScopeGuard {
pub(crate) fn new(expected_depth: usize) -> Self {
Self {
expected_depth,
is_async: false,
_not_send: std::marker::PhantomData,
}
}
pub(crate) fn new_async(expected_depth: usize) -> Self {
Self {
expected_depth,
is_async: true,
_not_send: std::marker::PhantomData,
}
}
pub(crate) fn noop() -> Self {
Self {
expected_depth: usize::MAX,
is_async: false,
_not_send: std::marker::PhantomData,
}
}
pub fn expected_depth(&self) -> usize {
self.expected_depth
}
}
impl Drop for ScopeGuard {
fn drop(&mut self) {
if self.is_async {
crate::async_ctx::pop_scope(self.expected_depth);
} else {
crate::sync_ctx::leave_scope(self.expected_depth);
}
}
}