我正在尝试将 a 传递String
给 clap 的构建器方法:
extern crate clap; // 2.32.0
use clap::App;
const NAME: &'static str = "example";
const DESC_PART_1: &'static str = "desc";
const DESC_PART_2: &'static str = "ription";
fn main() {
let description: String = format!("{}{}", DESC_PART_1, DESC_PART_2);
let matches = App::new(NAME).about(description).get_matches();
}
我得到错误:
error[E0277]: the trait bound `&str: std::convert::From<std::string::String>` is not satisfied
--> src/main.rs:11:34
|
11 | let matches = App::new(NAME).about(description).get_matches();
| ^^^^^ the trait `std::convert::From<std::string::String>` is not implemented for `&str`
|
= note: required because of the requirements on the impl of `std::convert::Into<&str>` for `std::string::String`
如果我通过了,我会收到类似的错误&description
。我正在努力理解这个错误的起源以及使用签名拍手的原因pub fn about<S: Into<&'b str>>(self, about: S) -> Self
。