1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#[macro_export]
macro_rules! classify_noderef {
    (? $e:expr) => {{
        let kind = match $e {
            None => NodeKind::None,
            Some(ref node) => classify_noderef!(node),
        };
        kind
    }};
    ($e:expr) => {{
        // Ensure references don't leak outside this macro.
        let kind = match *$e.borrow() {
            NodeBox::Internal(_) => NodeKind::Internal,
            NodeBox::Leaf(_) => NodeKind::Leaf,
        };
        kind
    }};
}

#[macro_export]
macro_rules! noderef_as {
    ($ref:expr, $type:ident) => {
        match *$ref.borrow() {
            NodeBox::$type(ref deref) => deref,
            _ => unreachable!(),
        }
    };
}

#[macro_export]
macro_rules! noderef_as_mut {
    ($ref:expr, $type:ident) => {
        match *$ref.borrow_mut() {
            NodeBox::$type(ref mut deref) => deref,
            _ => unreachable!(),
        }
    };
}