1use core::mem;
5
6#[derive(PartialEq, Eq, Clone, Copy, Debug)]
10pub enum FormatTag {
11 InsideChain,
12
13 AfterNewline,
21}
22
23#[derive(Clone, Copy, Debug)]
25pub struct FormatTags {
26 pub inside_chain: bool,
27 pub after_newline: bool,
28}
29
30impl FormatTags {
31 #[must_use]
33 pub const fn new() -> Self {
34 Self { inside_chain: false, after_newline: false, }
35 }
36
37 pub const fn add(&mut self, tag: FormatTag) -> bool {
41 self.set(tag, true)
42 }
43
44 pub const fn remove(&mut self, tag: FormatTag) -> bool {
48 self.set(tag, false)
49 }
50
51 pub const fn set(&mut self, tag: FormatTag, present: bool) -> bool {
55 match tag {
56 FormatTag::InsideChain => mem::replace(&mut self.inside_chain, present),
57 FormatTag::AfterNewline => mem::replace(&mut self.after_newline, present),
58 }
59 }
60
61 #[must_use]
63 pub const fn contains(&self, tag: FormatTag) -> bool {
64 match tag {
65 FormatTag::InsideChain => self.inside_chain,
66 FormatTag::AfterNewline => self.after_newline,
67 }
68 }
69}
70
71impl Default for FormatTags {
72 fn default() -> Self {
73 Self::new()
74 }
75}