1use crate::link::Link;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct Pattern {
9 pub index: String,
10 pub source: Option<Box<Pattern>>,
11 pub target: Option<Box<Pattern>>,
12}
13
14impl Pattern {
15 pub fn new(index: String, source: Option<Pattern>, target: Option<Pattern>) -> Self {
16 Self {
17 index,
18 source: source.map(Box::new),
19 target: target.map(Box::new),
20 }
21 }
22
23 pub fn is_leaf(&self) -> bool {
24 self.source.is_none() && self.target.is_none()
25 }
26}
27
28#[derive(Clone, Debug, Eq, PartialEq)]
29pub struct ResolvedLink {
30 pub index: u32,
31 pub source: u32,
32 pub target: u32,
33 pub name: Option<String>,
34}
35
36impl ResolvedLink {
37 pub fn new(index: u32, source: u32, target: u32, name: Option<String>) -> Self {
38 Self {
39 index,
40 source,
41 target,
42 name,
43 }
44 }
45
46 pub fn to_link(&self) -> Link {
47 Link::new(self.index, self.source, self.target)
48 }
49}