我想有两个相互冲突的选项,但也必须要求其中之一:
#[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