我试图通过编写命令行界面来学习rust,但我不能做通过功能的cargo run,我不明白为什么。我阅读了文档/堆栈,但我仍然不明白为什么会发生这种情况。感觉它应该是这样工作的https://doc.rust-lang.org/cargo/commands/cargo-run.html
我正在尝试运行这段代码
https://github.com/clap-rs/clap/blob/master/examples/17_yaml.rs
使用命令cargo run --features=yaml或cargo run --features yaml。我尝试了许多组合,但都不起作用。
我的Cargo.toml是这样的:
[dependencies.clap]
version = "*"
default-features = false
features = ["yaml"]当我运行时,我有错误:
:!cargo run --features=yaml
error: Package `fun v0.1.0 (/Users/XXX/Projekty/rust/fun)` does not have these fe
atures: `yaml`
shell returned 101我做错了什么?
发布于 2020-04-12 08:12:52
他们的代码要求您克隆clap存储库,将其更改到其目录中,然后从那里运行cargo run --features yaml --example 17_yaml。You can read more about how the cargo examples feature works here。
如果你打算以noted in that example code的身份复制他们的代码,你必须删除这个条件编译属性:
// Note: If you're using clap as a dependency and don't have a feature for your users called
// "yaml", you'll need to remove the #[cfg(feature = "yaml")] conditional compilation attribute
#[cfg(feature = "yaml")]
fn main() {否则,它将加载this other main implementation并发出该错误:
#[cfg(not(feature = "yaml"))]
fn main() {
// As stated above, if clap is not compiled with the YAML feature, it is disabled.
println!("YAML feature is disabled.");
println!("Pass --features yaml to cargo when trying this example.");
}您实际上不需要在命令行上传递--features,除非您是在如上所述的机箱内运行它们的示例。如果你正在复制他们的代码,你也应该删除整个函数!它只在作为示例运行时才相关。
https://stackoverflow.com/questions/61159287
复制相似问题