1pub trait State {
7 fn chain(&self) -> Vec<&'static str>;
8 fn link<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str>;
9}
10
11pub trait DerivedState<'valid>: State + Convert<'valid> {}
13
14pub trait Convert<'valid> {
16 fn convert<Current: State>(value: &'valid mut Current) -> Self;
17}
18
19
20pub struct Main {
26 pub chain: Vec<&'static str> = Vec::new()
27}
28
29impl State for Main {
31 fn chain(&self) -> Vec<&'static str> {return self.chain.clone()}
32 fn link<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return &mut self.chain}
33}
34
35
36pub struct Same<'this> {
42 link: &'this mut Vec<&'static str>
43}
44
45impl<'this> State for Same<'this> {
47 fn chain(&self) -> Vec<&'static str> {return self.link.clone()}
48 fn link<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
49}
50
51impl<'valid> DerivedState<'valid> for Same<'valid> {}
53
54impl<'valid> Convert<'valid> for Same<'valid> {
56 fn convert<Current: State>(value: &'valid mut Current) -> Self {
57 return Self {
58 link: value.link()
59 }
60 }
61}
62
63
64pub struct Name<'valid, const NAME: &'static str> {
70 link: &'valid mut Vec<&'static str>
71}
72
73impl<'this, const NAME: &'static str> State for Name<'this, NAME> {
75 fn chain(&self) -> Vec<&'static str> {return self.link.clone()}
76 fn link<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
77}
78
79impl<'valid, const NAME: &'static str> Drop for Name<'valid, NAME> {
81 fn drop(&mut self) {self.link.pop();}
82}
83
84impl<'valid, const NAME: &'static str> DerivedState<'valid> for Name<'valid, NAME> {}
86
87impl<'valid, const NAME: &'static str> Convert<'valid> for Name<'valid, NAME> {
89 fn convert<Current: State>(value: &'valid mut Current) -> Self {
90 value.link().push(NAME);
91 return Self {
92 link: value.link()
93 }
94 }
95}