Skip to content

Commit

Permalink
fix item35 miss note
Browse files Browse the repository at this point in the history
  • Loading branch information
lispking committed Aug 7, 2024
1 parent 864c71d commit 3302a16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/chapter_6/item35-bindgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ include!("generated.rs");

这也意味着 bindgen 步骤是理想的候选者,可以包含在 CI 系统([第 32 条])中;如果生成的代码包含在源码控制中,CI 系统可以在新生成的文件与检入的版本不匹配时报错。

当您处理具有大量 API 的现有 C 代码库时,bindgen 工具才能真正发挥其作用。为一个庞大的 `lib_api.h` 头文件创建 Rust 等价物是手动且乏味的,因此容易出错 —— 并且如前所述,许多不匹配错误的类别不会被工具链检测到。bindgen 还拥有一系列选项,允许针对 API 的特定子集(比如,之前展示的 -- `allowlist-function``--allowlist-type` 选项)。
当您处理具有大量 API 的现有 C 代码库时,bindgen 工具才能真正发挥其作用。为一个庞大的 `lib_api.h` 头文件创建 Rust 等价物是手动且乏味的,因此容易出错 —— 并且如前所述,许多不匹配错误的类别不会被工具链检测到。bindgen 还拥有一系列选项,允许针对 API 的特定子集(比如,之前展示的 -- `allowlist-function``--allowlist-type` 选项)。[^1]

这也允许采用分层方法在 Rust 中暴露现有的 C 库;包装某个 xyzzy 库的一个常见约定是拥有以下内容:
* 一个仅包含 bindgen 生成的代码的 `xyzzy-sys crate` —— 其使用必然是不安全的。
Expand Down

0 comments on commit 3302a16

Please sign in to comment.