是否可以对 Cargo.toml 中的外部代码应用补丁?

Is it possible to apply a patch to external code in Cargo.toml?

我阅读了 Cargo 手册about the patch option,但我仍然不清楚。

是否可以指示Cargo:

  1. 从此存储库获取代码。
  2. 将此补丁文件 (my_cool_change.patch) 应用于该代码。

我自己创建项目的分支是唯一的方法吗?

无法指示 Cargo 执行类似 "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it" 的操作。

Cargo 文档没有骗你:你需要 fork 你想要更改的项目,根据需要进行更改,然后用你的 fork 版本替换依赖项。