rep
Rep is a small tool for checking representation/class invariants. As programmers, we should care about correctness at compile time and at run time. We should care about our data structures being correct. Rep is a small tool that lets you do 2 things.
- Define a correct representation (a rep/class invariant)
- Insert runtime checks (rep checks)
some examples
We can start off with a simple data structure.
use *;
The CheckRep
trait can be implemented. This serves as a definition of correct representation.
Now we can use the #[check_rep]
macro to automatically insert calls to check_rep
at start and end of all methods that are pub
and mutate &mut self
. We can also manually make calls to check_rep
wherever we so desire.
// <-- this inserts calls to check_rep at start and end of move_by
some more examples
For simple representations, we can even derive an implementation of CheckRep
.
usage
Just add the following to your Cargo.toml
file.
[]
= "0.1.0"
Then you can begin defining representations and improving the safety of your software.