1use crate::link::GenericLink;
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 GenericResolvedLink<T> {
30 pub index: T,
31 pub source: T,
32 pub target: T,
33 pub name: Option<String>,
34}
35
36impl<T: Copy> GenericResolvedLink<T> {
37 pub fn new(index: T, source: T, target: T, name: Option<String>) -> Self {
38 Self {
39 index,
40 source,
41 target,
42 name,
43 }
44 }
45
46 pub fn to_link(&self) -> GenericLink<T> {
47 GenericLink::new(self.index, self.source, self.target)
48 }
49}
50
51pub type ResolvedLink = GenericResolvedLink<u32>;