struct Container<const INDEX: usize>;
trait Message {
const STR: &str = "";
type NEXT: Message;
const END: bool = false;
}
trait Is<T> {}
impl<T> Is<T> for T {}
trait Final {}
const LENGTH: usize = {
const fn get_length<const INDEX: usize>() -> usize
where
Container<INDEX>: Final,
{
INDEX
}
get_length()
};
struct Switch0<T, const BOOL: bool>(core::marker::PhantomData<T>);
struct Switch1<T, const BOOL: bool>(core::marker::PhantomData<T>);
struct Switch2<T, const BOOL: bool>(core::marker::PhantomData<T>);
impl Message for Container<0> {
type NEXT = Self;
const END: bool = true;
}
impl<T: Is<Container<0>>> Final for T where Switch0<T, true>: Unpin {}
fn __internal_collect_messages<T: Message>() {
if T::END {
return;
}
{
println!("{}", T::STR);
};
__internal_collect_messages::<T::NEXT>();
}
fn collect_messages() {
__internal_collect_messages::<Container<{ LENGTH }>>();
}
impl Message for Container<1> {
const STR: &str = "Hello world!";
type NEXT = Container<0>;
}
impl<T> Unpin for Switch0<T, false> {}
impl<T: Is<Container<1>>> Final for T where Switch1<T, true>: Unpin {}
fn main() {
collect_messages();
}
impl Message for Container<2> {
const STR: &str = "Hello again!";
type NEXT = Container<1>;
}
impl<T> Unpin for Switch1<T, false> {}
impl<T: Is<Container<2>>> Final for T where Switch2<T, true>: Unpin {}