Show HN: Zig-DbC – Zig 语言的契约式设计库

4作者: habedi09 个月前
大家好, 我创建了一个开源库,用于在 Zig 编程语言中使用契约式设计 (DbC) 原则。 它名为 Zig-DbC,目前提供以下功能: - 一个简单的 API,用于定义前置条件、后置条件和不变量。 - 契约在 `Debug`、`ReleaseSafe` 和 `ReleaseSmall` 模式下生效,以便尽早发现错误。 - 在 `ReleaseFast` 模式下,所有检查都在编译时移除,零性能开销。 - 一个可选模式,用于处理返回错误的函数中的部分状态更改。 - 透明的错误处理,将代码中的错误传播给调用者。 项目 GitHub 仓库:<a href="https://github.com/habedi/zig-dbc" rel="nofollow">https://github.com/habedi/zig-dbc</a>
查看原文
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>