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
39
40
41
42
43
44
45
use crate::*;
use alloc::string::{String, ToString};
use ritelinked::LinkedHashMap;
pub type AnchorBase<R> = LinkedHashMap<String, NodeBase<R>>;
pub type Anchors = AnchorBase<repr::RcRepr>;
pub type ArcAnchors = AnchorBase<repr::ArcRepr>;
pub fn anchor_visit<R: repr::Repr>(n: &NodeBase<R>) -> AnchorBase<R> {
let mut visitor = AnchorBase::new();
inner_anchor_visit(n, &mut visitor);
visitor
}
fn inner_anchor_visit<R: repr::Repr>(n: &NodeBase<R>, visitor: &mut AnchorBase<R>) {
if !n.anchor().is_empty() {
visitor.insert(n.anchor().to_string(), n.clone());
}
match n.yaml() {
YamlBase::Seq(a) => {
for n in a {
inner_anchor_visit(n, visitor);
}
}
YamlBase::Map(m) => {
for (k, v) in m {
inner_anchor_visit(k, visitor);
inner_anchor_visit(v, visitor);
}
}
_ => {}
}
}