meta_language/
substitution.rs1use crate::link_network::LinkId;
2
3#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct SubstitutionRule {
6 pattern: Vec<LinkId>,
7 replacement: Vec<LinkId>,
8}
9
10impl SubstitutionRule {
11 #[must_use]
14 pub fn new<const P: usize, const R: usize>(
15 pattern: [LinkId; P],
16 replacement: [LinkId; R],
17 ) -> Self {
18 Self {
19 pattern: pattern.to_vec(),
20 replacement: replacement.to_vec(),
21 }
22 }
23
24 #[must_use]
26 pub fn create<const R: usize>(replacement: [LinkId; R]) -> Self {
27 Self {
28 pattern: Vec::new(),
29 replacement: replacement.to_vec(),
30 }
31 }
32
33 #[must_use]
35 pub fn delete<const P: usize>(pattern: [LinkId; P]) -> Self {
36 Self {
37 pattern: pattern.to_vec(),
38 replacement: Vec::new(),
39 }
40 }
41
42 pub(crate) fn pattern(&self) -> &[LinkId] {
43 &self.pattern
44 }
45
46 pub(crate) fn replacement(&self) -> &[LinkId] {
47 &self.replacement
48 }
49}
50
51#[derive(Clone, Debug, Default, PartialEq, Eq)]
53pub struct SubstitutionReport {
54 pub(crate) created: Vec<LinkId>,
55 pub(crate) updated: Vec<LinkId>,
56 pub(crate) deleted: Vec<LinkId>,
57}
58
59impl SubstitutionReport {
60 #[must_use]
62 pub fn created(&self) -> &[LinkId] {
63 &self.created
64 }
65
66 #[must_use]
68 pub fn updated(&self) -> &[LinkId] {
69 &self.updated
70 }
71
72 #[must_use]
74 pub fn deleted(&self) -> &[LinkId] {
75 &self.deleted
76 }
77}