知识卡片
公共接口文档写契约
公共接口文档可按用途、用例及调用契约组织。用 Examples 给最短用法,Panics 写出触发 panic 的条件,Errors 描述会返回的错误,Safety 解释调用 unsafe 接口必须维持的约束。仅写与该项有关的栏目。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 深入 Cargo 与 Crates.io Publishing a Crate to Crates.io · 查看原书依据
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.
参考来源
- 位置:《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.