向cargo run传递默认参数

3
我有以下二进制箱体源代码结构:
prj
 |
 |__config
 |    |___conf.toml
 |
 |___src
 |    |_...
 |
 |__Cargo.toml

因此,在执行cargo run时,我期望以下命令被运行:bin /path/to/prj/config/conf.toml

是否可以在Cargo.toml中配置cargo run,以便每次不必显式传递绝对路径到config/conf.toml

1个回答

4
有没有可能在 Cargo.toml 中配置 cargo run,以便每次不需要显式传递,就可以将绝对路径传递给 config/conf.toml
不是“完全”可以,但是可以通过其配置文件中的命令别名来配置 Cargo。例如,您可以将以下内容放入 ${PROJECT_ROOT}/.cargo/config.toml
[alias]
runx = "run /path/to/config/conf.toml"

然后你只需要执行 cargo runx 命令。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接