-3

我正在使用 Rust 的structoptcrate,但是当我尝试编译示例时,出现以下错误,

error[E0277]: the trait bound `String: From<&OsStr>` is not satisfied
   --> bin/seq.rs:21:36
    |
21  |     #[structopt(short, long, parse(from_os_str))]
    |                                    ^^^^^^^^^^^ the trait `From<&OsStr>` is not implemented for `String`
    |
    = help: the following implementations were found:
              <String as From<&String>>
              <String as From<&mut str>>
              <String as From<&str>>
              <String as From<Box<str>>>
            and 2 others
note: required by `from`
4

1 回答 1

0

您可以通过可靠的转换将 a 转换String为 aOsString,但不能将 a 转换OsString为 a String

这是因为 anOsStr接受无效的东西,Strings因此无法确保解析为的 anOsStr可以structopt转换为String.

你可能根本不需要parse()

#[structopt(short, long)]

不是

#[structopt(short, long, parse(from_os_str))]
于 2021-10-04T03:59:16.580 回答