Skip to main content

libutils_report/
state.rs

1//^
2//^ STATE
3//^
4
5//> STATE -> BASE
6pub const trait State {
7    fn get<'valid>(&'valid self) -> &'valid Vec<&'static str>;
8    fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str>;
9}
10
11//> STATE -> DERIVED
12pub const trait DerivedState<'valid>: const State + const Convert<'valid> {}
13
14//> STATE -> CONVERT
15pub const trait Convert<'valid> {
16    fn convert<Current: const State>(value: &'valid mut Current) -> Self;
17}
18
19
20//^
21//^ MAIN
22//^
23
24//> MAIN -> STRUCT
25pub struct Main {
26    pub chain: Vec<&'static str> = Vec::new()
27}
28
29//> MAIN -> STATE
30const impl State for Main {
31    fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return &self.chain}
32    fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return &mut self.chain}
33}
34
35
36//^
37//^ SAME
38//^
39
40//> SAME -> STRUCT
41pub struct Same<'this> {
42    link: &'this mut Vec<&'static str>
43} 
44
45//> SAME -> STATE
46const impl<'this> State for Same<'this> {
47    fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return self.link}
48    fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
49}
50
51//> SAME -> DERIVED STATE
52const impl<'valid> DerivedState<'valid> for Same<'valid> {}
53
54//> SAME -> CONVERT
55const impl<'valid> Convert<'valid> for Same<'valid> {
56    fn convert<Current: const State>(value: &'valid mut Current) -> Self {
57        return Self {
58            link: value.get_mut()
59        }
60    }
61}
62
63
64//^
65//^ NAME
66//^
67
68//> NAME -> STRUCT
69pub struct Name<'valid, const NAME: &'static str> {
70    link: &'valid mut Vec<&'static str>
71} 
72
73//> NAME -> STATE
74const impl<'this, const NAME: &'static str> State for Name<'this, NAME> {
75    fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return self.link}
76    fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
77} 
78
79//> NAME -> DROP
80impl<'valid, const NAME: &'static str> Drop for Name<'valid, NAME> {
81    fn drop(&mut self) {self.link.pop();}
82}
83
84//> NAME -> DERIVED STATE
85const impl<'valid, const NAME: &'static str> DerivedState<'valid> for Name<'valid, NAME> {}
86
87//> NAME -> CONVERT
88const impl<'valid, const NAME: &'static str> Convert<'valid> for Name<'valid, NAME> {
89    fn convert<Current: const State>(value: &'valid mut Current) -> Self {
90        let link = value.get_mut();
91        link.push(NAME);
92        return Self {
93            link: link
94        }
95    }
96}