我相对来说是 Rust 的新手,正在尝试做以下事情:
pub fn route(request: &[String]) {
let commands = ["one thing", "another thing", "something else"];
for command in commands.iter() {
if command == request {
// do something
} else {
// throw error
}
}
}
当我尝试构建这个时,会出现编译器错误:
error[E0277]: the trait bound `&str: std::cmp::PartialEq<[std::string::String]>` is not satisfied
--> src/main.rs:5:20
|
5 | if command == request {
| ^^ can't compare `&str` with `[std::string::String]`
|
= help: the trait `std::cmp::PartialEq<[std::string::String]>` is not implemented for `&str`
= note: required because of the requirements on the impl of `std::cmp::PartialEq<&[std::string::String]>` for `&&str`
str
与String
无关。 - mcarton