You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 12:01:08