如何在cargo watch中实现--manifest-path参数的功能?
解决cargo watch无法使用--manifest-path参数的替代方案
不用切换目录的话,直接把--manifest-path参数放到-x指定的cargo子命令里就行——cargo watch的-x是用来传递完整cargo命令的,它本身不单独处理--manifest-path这类cargo核心参数。
具体用法示例:
- 自动重建并运行指定路径的项目:
cargo watch -x 'run --manifest-path /path/to/your/Cargo.toml' - 需要执行多步命令(比如先检查代码再运行):
cargo watch -x 'check --manifest-path /path/to/your/Cargo.toml' -x 'run --manifest-path /path/to/your/Cargo.toml'
原理很直接:cargo watch会把-x后面的内容完整传递给cargo执行,所以把原本给cargo run的参数直接跟在run后面,就能让它正确识别指定路径的Cargo.toml,完全不需要切换工作目录。
内容的提问来源于stack exchange,提问作者TheDarkHoarse
相关产品推荐
相关产品推荐

