← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6075.a.5 · 生成模型:未记录

公共接口文档写契约

理解等级:中级

公共接口文档可按用途、用例及调用契约组织。用 Examples 给最短用法,Panics 写出触发 panic 的条件,Errors 描述会返回的错误,Safety 解释调用 unsafe 接口必须维持的约束。仅写与该项有关的栏目。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第14章 深入 Cargo 与 Crates.io(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c14.xhtml`,块 0042) - 结论依据:Safety 段例子表明文档还要说明调用前提和需维持的不变量。 - 原始内容:Safety If the function is unsafe to call (we discuss unsafety in Chapter 19), there should be a section explaining why the function is unsafe and covering the invariants that the function expects callers to uphold.