pub const trait State {
fn get<'valid>(&'valid self) -> &'valid Vec<&'static str>;
fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str>;
}
pub const trait DerivedState<'valid>: const State + const Convert<'valid> {}
pub const trait Convert<'valid> {
fn convert<Current: const State>(value: &'valid mut Current) -> Self;
}
pub struct Main {
pub chain: Vec<&'static str> = Vec::new()
}
const impl State for Main {
fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return &self.chain}
fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return &mut self.chain}
}
pub struct Same<'this> {
link: &'this mut Vec<&'static str>
}
const impl<'this> State for Same<'this> {
fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return self.link}
fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
}
const impl<'valid> DerivedState<'valid> for Same<'valid> {}
const impl<'valid> Convert<'valid> for Same<'valid> {
fn convert<Current: const State>(value: &'valid mut Current) -> Self {
return Self {
link: value.get_mut()
}
}
}
pub struct Name<'valid, const NAME: &'static str> {
link: &'valid mut Vec<&'static str>
}
const impl<'this, const NAME: &'static str> State for Name<'this, NAME> {
fn get<'valid>(&'valid self) -> &'valid Vec<&'static str> {return self.link}
fn get_mut<'valid>(&'valid mut self) -> &'valid mut Vec<&'static str> {return self.link}
}
impl<'valid, const NAME: &'static str> Drop for Name<'valid, NAME> {
fn drop(&mut self) {self.link.pop();}
}
const impl<'valid, const NAME: &'static str> DerivedState<'valid> for Name<'valid, NAME> {}
const impl<'valid, const NAME: &'static str> Convert<'valid> for Name<'valid, NAME> {
fn convert<Current: const State>(value: &'valid mut Current) -> Self {
let link = value.get_mut();
link.push(NAME);
return Self {
link: link
}
}
}