小编Zac*_*h W的帖子

如何使用 clap 来创建向量

我有一个像这样的基本结构

pub struct Args {
  #[clap(short, long, value_parser)]
  pub files: Vec<String>,
}
Run Code Online (Sandbox Code Playgroud)

我试图让这个结构体采用多个这样的值

cargo run -- --files hello world
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,它看不world正确。这是错误的:

error: Found argument 'world' which wasn't expected, or isn't valid in this context
Run Code Online (Sandbox Code Playgroud)

让 clap 填充此结构的正确方法是什么?

rust clap

7
推荐指数
1
解决办法
4460
查看次数

如何在 C# 中传递私有变量作为默认可选参数

在提供的示例中,函数声明PrintBar抛出错误,因为_bar不是编译时常量。避免此问题的最佳做法是什么?

using System;

class Foo
{
    private readonly string _bar;
    public Foo(string initBar)
    {
        _bar = initBar;
    }

    public void PrintBar(string value = _bar)
    {
        Console.WriteLine(value);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# optional-parameters

2
推荐指数
1
解决办法
268
查看次数

标签 统计

c# ×1

clap ×1

optional-parameters ×1

rust ×1