我有一个非常简单的方法。第一个参数接受向量分量 ("A", 5, 0),我会将其与另一个向量的每个元素进行比较,看看它们是否具有相同的 ( _ , 5 , _ ),然后打印出找到的元素的字符串。
比较 ("A", 5, 0 ) 和 ("Q", 5, 2) 应打印出 Q。
fn is_same_space(x: &str, y1: i32, p: i32, vector: &Vec<(&str, i32, i32)>) -> (&str) {
let mut foundString = "";
for i in 0..vector.len() {
if y1 == vector[i].1 {
foundString = vector[i].0;
}
}
foundString
}
但是,我收到这个错误
error[E0106]: missing lifetime specifier
--> src/main.rs:1:80
|
1 | fn is_same_space(x: &str, y1: i32, p: i32, vector: &Vec<(&str, i32, i32)>) -> (&str) {
| ^ expected lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or one of `vector`'s 2 elided lifetimes