kodept_ast/graph/
nodes.rs

1use std::fmt::{Debug, Formatter};
2
3use derive_more::{Deref, DerefMut, From};
4use qcell::{TLCell, TLCellOwner};
5
6use crate::graph::AnyNode;
7
8type CellImpl<T> = TLCell<Ghost, T>;
9type CellOwnerImpl = TLCellOwner<Ghost>;
10
11#[derive(Debug)]
12pub struct Ghost;
13
14#[derive(Deref, From)]
15#[repr(transparent)]
16pub struct Inaccessible<T = AnyNode>(CellImpl<T>);
17
18#[derive(Deref, DerefMut, From)]
19pub struct PermTkn(CellOwnerImpl);
20
21pub type RefNode<'arena, T = AnyNode> = &'arena Inaccessible<T>;
22
23impl<T> Inaccessible<T> {
24    pub fn new<U: Into<T>>(data: U) -> Self {
25        Self(TLCell::new(data.into()))
26    }
27}
28
29impl Default for PermTkn {
30    /// Value of this type should be a singleton in one thread
31    /// If this contract violated, function will panic
32    fn default() -> Self {
33        Self(TLCellOwner::new())
34    }
35}
36
37impl PermTkn {
38    pub fn new() -> Self {
39        Self::default()
40    }
41}
42
43impl<T: Debug> Debug for Inaccessible<T> {
44    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
45        f.debug_struct("Inaccessible").finish_non_exhaustive()
46    }
47}
48
49impl Debug for PermTkn {
50    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51        f.debug_struct("PermissionToken").finish_non_exhaustive()
52    }
53}