syntree/builder/
checkpoint.rs1use core::cell::Cell;
2
3use alloc::rc::Rc;
4
5#[derive(Debug, Clone)]
14#[repr(transparent)]
15pub struct Checkpoint<P>(Rc<Cell<Inner<P>>>)
16where
17 P: Copy;
18
19impl<P> Checkpoint<P>
20where
21 P: Copy,
22{
23 pub(crate) fn new(node: P, parent: Option<P>) -> Self {
24 Self(Rc::new(Cell::new(Inner { node, parent })))
25 }
26
27 pub(crate) fn set(&self, node: P, parent: Option<P>) {
28 self.0.set(Inner { node, parent });
29 }
30
31 pub(crate) fn node(&self) -> P {
32 self.0.get().node
33 }
34
35 pub(crate) fn get(&self) -> (P, Option<P>) {
36 let Inner { node, parent } = self.0.get();
37 (node, parent)
38 }
39}
40
41#[derive(Debug, Clone, Copy)]
43struct Inner<P> {
44 node: P,
46 parent: Option<P>,
48}