作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想有两个相互冲突的选项,但其中一个必须是必需的:
#[macro_use]
extern crate structopt;
use structopt::StructOpt;
#[derive(StructOpt)]
struct Opt {
#[structopt(
long = "foo",
required_unless = "bar",
conflicts_with = "bar",
)]
foo: Option<String>,
#[structopt(
long = "bar",
required_unless = "foo"),
]
bar: Option<String>,
}
fn main() {
let args = Opt::from_args();
println!("{:?}", args.foo);
println!("{:?}", args.bar);
}
这是编译器 (v1.28.0) 提示的地方:
error: proc-macro derive panicked
--> src/main.rs:6:10
|
6 | #[derive(StructOpt)]
| ^^^^^^^^^
|
= help: message: invalid structopt syntax: attr
最佳答案
#[stuff(...),]
末尾带有额外的 ,
不是有效的属性语法。如果您修复此拼写错误,您的代码可以正常工作。
#[structopt(
long = "bar",
required_unless = "foo", // no `)` on this line.
)] // put `)` on this line, no `,` after it
bar: Option<String>,
关于rust - 使用 required_unless 和 conflicts_with 的 structopt 的 proc-macro panic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51750975/
我在使用 required_unless 验证时遇到问题。 我想做的是说当 building number 为 empty 或其他方式时 building name 是必需的,所以 building当
我已经在 Laravel 中完成了验证。我从 Laravel Validations Rules 中获取了很多验证规则 我想为以下条件使用 required_unless 规则。 $rules = a
我想有两个相互冲突的选项,但其中一个必须是必需的: #[macro_use] extern crate structopt; use structopt::StructOpt; #[derive(St
我是一名优秀的程序员,十分优秀!