I've made an open-source library for using design by contract (DbC) principles in the Zig programming language.
It's called Zig-DbC, and it currently provides the following features:
- A simple API to define preconditions, postconditions, and invariants.
- Contracts are active in `Debug`, `ReleaseSafe`, and `ReleaseSmall` modes to catch bugs early.
- All checks are removed at compile time in `ReleaseFast` mode for zero performance cost.
- An optional mode to handle partial state changes in functions that return errors.
- Transparent error handling that propagates errors from your code to the caller.
Project's GitHub repo: https://github.com/habedi/zig-dbc
I am not yet proficient enough in Zig to be able to evaluate how well the syntax fits into idiomatic Zig.
Good work.
I'm new to Zig myself and created this library because I had trouble verifying the correctness of the code I wrote for a set of complex data structures in another larger Zig project (this one: https://github.com/habedi/ordered). I'm currently experimenting with how to use DbC in Zig, which led to the creation of this library.