This really reminds me of design by contract, which I find absolutely fascinating.
Another library that implements this, albeit at runtime (and optionally using MIRAI is https://docs.rs/contracts/latest/contracts/
Hey there. My name's Michiel and I'm a software engineer working in London. If you want to reach out, my email is michielalexanderb (at) gmail.com.
[ my public key: https://keybase.io/michielboekhoff; my proof: https://keybase.io/michielboekhoff/sigs/PetIJ2iVv-joJeIHuUSdM5XrysEbjJ_h7_aIO9GPNbY ]