<a href="https:&#x2F;&#x2F;github.com&#x2F;Munksgaard&#x2F;rust-sessions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Munksgaard&#x2F;rust-sessions</a> actually goes quite far in doing this (without compiler support, just using the type system).