/// A case is a self-referential container of a value.
///
/// Cases are lazily evaluated on first access.
trait Case<'a> {
type Output;
fn get(self: Pin<&'a Self>) -> Self::Output;
}
Self-referential data has been a pain point for a while. Current solutions leave much to be desired, and are outside of the standard library.
Case utilizes the existing coroutine transform within the compiler to create a self-referential scope. Once pinned (either through std::pin::pin! or Box::pin), it can be evaluated and return values that reference its interior.
Case is always !Sync (it contains interior mutability) and requires a lock in threaded scenarios.
Case is dyn safe, so Box<dyn for<'a> Case<'a, &'a [u8]>> is fully supported.
In addition to allocations, nolife also requires the implementation of the nolife::Family trait. For Case, the higher kinded type "hack" is an implementation detail.
The nightly features are only needed for the example implementation, the trait itself does not require any.
The hkt + unsafe binder allows passing types by value out of the coroutine. I don't see a way you could do this using a Future on stable Rust. Pass by pointer is possible with a Future but it's an extra layer of indirection.
Never type is used because why not ¯\_(ツ)_/¯. It could be replaced with std::convert::Infallible, the effect is the same.