展示 HN:Zig-DbC – 一款用于 Zig 的契约设计库

4作者: habedi0大约 1 个月前原帖
大家好, 我制作了一个开源库,用于在Zig编程语言中使用契约设计(DbC)原则。 这个库叫做Zig-DbC,目前提供以下功能: - 一个简单的API,用于定义前置条件、后置条件和不变式。 - 在`Debug`、`ReleaseSafe`和`ReleaseSmall`模式下,契约是激活的,以便尽早捕捉错误。 - 在`ReleaseFast`模式下,所有检查在编译时被移除,确保零性能损耗。 - 一个可选模式,用于处理返回错误的函数中的部分状态变化。 - 透明的错误处理机制,将错误从您的代码传播到调用者。 项目的GitHub仓库:[https://github.com/habedi/zig-dbc](https://github.com/habedi/zig-dbc)
查看原文
Hi everyone,<p>I&#x27;ve made an open-source library for using design by contract (DbC) principles in the Zig programming language.<p>It&#x27;s called Zig-DbC, and it currently provides the following features:<p>- A simple API to define preconditions, postconditions, and invariants.<p>- Contracts are active in `Debug`, `ReleaseSafe`, and `ReleaseSmall` modes to catch bugs early.<p>- All checks are removed at compile time in `ReleaseFast` mode for zero performance cost.<p>- An optional mode to handle partial state changes in functions that return errors.<p>- Transparent error handling that propagates errors from your code to the caller.<p>Project&#x27;s GitHub repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;habedi&#x2F;zig-dbc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;habedi&#x2F;zig-dbc</a>