rust 我试图让clap builder接受argGroup的argg!,但我找不到我缺少的东西,

hfsqlsce  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(45)

此代码

.subcommand(
        Command::new("print")
            .alias("p")
            .arg(arg!(<address>  "address of value to print"))
            .group(
                ArgGroup::new("format")
                    .arg(arg!(integer: -i   "int"))
                    .arg(arg!(pointe: -p   "pointer"))
                    .required(true),
            )
            .about("delete breakpoint")
            .help_template(APPLET_TEMPLATE),
    )

字符串
产生了我不理解的错误 Storm

--> src\shell.rs:388:34
    |
388 | ...                   .arg(arg!(integer: -i   "int"))
    |                        --- ^^^^^^^^^^^^^^^^^^^^^^^^^
    |                        |   |
    |                        |   the trait `From<Arg>` is not implemented for `Id`
    |                        |   this tail expression is of type `Arg`
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              <Id as From<Str>>
              <Id as From<&Id>>
              <Id as From<&Str>>
              <Id as From<&&'static str>>
              <Id as From<&'static str>>
    = note: required for `Arg` to implement `Into<Id>`
    = note: required for `Arg` to implement `IntoResettable<Id>`
note: required by a bound in `ArgGroup::arg`
   --> C:\Users\paulm\.cargo\registry\src\index.crates.io-6f17d22bba15001f\clap_builder-4.4.12\src\builder\arg_group.rs:157:39
    |
157 |     pub fn arg(mut self, arg_id: impl IntoResettable<Id>) -> Self {
    |                                       ^^^^^^^^^^^^^^^^^^ required by this bound in `ArgGroup::arg`

error[E0277]: the trait bound `Id: From<Arg>` is not satisfied
   --> src\shell.rs:389:34
    |
389 | ...                   .arg(arg!(pointe: -p   "pointer"))
    |                        --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                        |   |
    |                        |   the trait `From<Arg>` is not implemented for `Id`
    |                        |   this tail expression is of type `Arg`
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              <Id as From<Str>>
              <Id as From<&Id>>
              <Id as From<&Str>>
              <Id as From<&&'static str>>
              <Id as From<&'static str>>
    = note: required for `Arg` to implement `Into<Id>`
    = note: required for `Arg` to implement `IntoResettable<Id>`
note: required by a bound in `ArgGroup::arg`
   --> C:\Users\paulm\.cargo\registry\src\index.crates.io-6f17d22bba15001f\clap_builder-4.4.12\src\builder\arg_group.rs:157:39
    |
157 |     pub fn arg(mut self, arg_id: impl IntoResettable<Id>) -> Self {
    |                                       ^^^^^^^^^^^^^^^^^^ required by this bound in `ArgGroup::arg`


我认为它试图说它不能从arg!宏调用中计算出ID,但是我已经尝试了许多arg!语法的组合,所有这些都产生了相同的错误。

  • clap 4.4.12
  • clap派生4.4.7
guz6ccqo

guz6ccqo1#

我现在明白了。参数必须单独指定,然后放在一个组中
这样

.subcommand(
    Command::new("print")
        .alias("p")
        .arg(arg!(<address>  "address of value to print"))
        .arg(arg!(asint: -i "int"))
        .arg(arg!(aspointer: -p   "pointer"))
        .arg(arg!(astring: -s   "string"))
        .group(
            ArgGroup::new("format")
                .args(["asint", "aspointer", "astring"])
                .required(true),
        )
        .about("delete breakpoint")
        .help_template(APPLET_TEMPLATE),
)

字符串

相关问题