ass_core/analysis/styles/validation/
inheritance.rs1use alloc::vec::Vec;
7
8#[derive(Debug, Clone)]
10pub struct StyleInheritance<'a> {
11 pub name: &'a str,
13 pub parents: Vec<&'a str>,
15 pub children: Vec<&'a str>,
17 pub depth: usize,
19 pub has_circular_inheritance: bool,
21}
22
23impl<'a> StyleInheritance<'a> {
24 #[must_use]
26 pub const fn new(name: &'a str) -> Self {
27 Self {
28 name,
29 parents: Vec::new(),
30 children: Vec::new(),
31 depth: 0,
32 has_circular_inheritance: false,
33 }
34 }
35
36 pub fn add_parent(&mut self, parent: &'a str) {
38 if !self.parents.contains(&parent) {
39 self.parents.push(parent);
40 }
41 }
42
43 pub fn set_parent(&mut self, parent: &'a str) {
45 self.parents.clear();
46 self.parents.push(parent);
47 self.depth = 1; }
49
50 pub fn add_child(&mut self, child: &'a str) {
52 if !self.children.contains(&child) {
53 self.children.push(child);
54 }
55 }
56
57 #[must_use]
59 pub fn has_inheritance(&self) -> bool {
60 !self.parents.is_empty() || !self.children.is_empty()
61 }
62
63 #[must_use]
65 pub fn is_root(&self) -> bool {
66 self.parents.is_empty()
67 }
68
69 #[must_use]
71 pub fn is_leaf(&self) -> bool {
72 self.children.is_empty()
73 }
74}