structopt: error[E0277]: trait bound `String: From<&OsStr>`
structopt: error[E0277]: the trait bound `String: From<&OsStr>`
我正在使用 Rust 的 structopt
crate,但是当我尝试编译示例时出现以下错误,
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`
您可以将 String
into a OsString
转换为绝对正确的转换,但不能将 OsString
转换为 String
。
这是因为 OsStr
接受无效的东西 Strings
所以没有办法确保 structopt
解析成的 OsStr
可以转换为String
.
您可能根本不需要 parse()
,
#[structopt(short, long)]
没有
#[structopt(short, long, parse(from_os_str))]
我正在使用 Rust 的 structopt
crate,但是当我尝试编译示例时出现以下错误,
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`
您可以将 String
into a OsString
转换为绝对正确的转换,但不能将 OsString
转换为 String
。
这是因为 OsStr
接受无效的东西 Strings
所以没有办法确保 structopt
解析成的 OsStr
可以转换为String
.
您可能根本不需要 parse()
,
#[structopt(short, long)]
没有
#[structopt(short, long, parse(from_os_str))]