cargo 是否有能力检测源变化?

Does cargo have the ability to detect source changes?

有没有一种方法可以完成 cargo run 的等效操作,但只有在源文件发生更改时才重新编译,例如 make

. ├── Cargo.lock ├── Cargo.toml ├── input.txt ├── README.md └── src ├── dna.rs ├── dynamic.rs ├── lib.rs └── main.rs

编辑:添加了 tree 输出。

Cargo 默认执行此操作。

创建一个新项目:

$ cargo new --bin foo
$ cd foo/

运行它:

$ cargo run
   Compiling foo v0.0.1 (file:///private/tmp/foo)
     Running `target/foo`
Hello, world!

运行第二次,没有任何改变:

$ cargo run
     Running `target/foo`
Hello, world!

并更新文件并再次运行:

$ touch src/main.rs
$ cargo run
   Compiling foo v0.0.1 (file:///private/tmp/foo)
     Running `target/foo`
Hello, world!

请注意第二个 运行 中缺少 Compiling foo...。修改文件时(这里使用touch),重新编译

为了它的价值,我正在使用 cargo 0.0.1-pre-nightly (66849de 2015-03-10) (built 2015-03-11)

回答你在标题中提出的问题,"Does cargo have the ability to detect source changes?",答案是肯定的,cargo watch。它是 cargo 的扩展,因此您必须下载并编译它才能使用它。 https://github.com/passcod/cargo-watch

当然,从你的详细问题来看,这显然不是你要问的问题,但看到标题并单击 link 的其他人可能确实想要该问题的答案。