0
這很簡單,但我不知道爲什麼它不起作用。向量元組字符串連接
fn main() {
let vector = vec![("foo".to_string(), "bar".to_string())];
let string = vector[0].0 + vector[0].1;
}
錯誤
src/main.rs:3:29: 3:40 error: mismatched types:
expected `&str`,
found `collections::string::String`
(expected &-ptr,
found struct `collections::string::String`) [E0308]
src/main.rs:3 let string = vector[0].0 + vector[0].1;
^~~~~~~~~~~
所以後來我就改成這樣:
fn main() {
let vector = vec![("foo".to_string(), "bar".to_string())];
let string = &*vector[0].0 + &*vector[0].1;
}
收到其他錯誤
src/main.rs:3:15: 3:28 error: binary operation `+` cannot be applied to type `&str` [E0369]
src/main.rs:3 let string = &*vector[0].0 + &*vector[0].1;
^~~~~~~~~~~~~
src/main.rs:3:15: 3:28 help: run `rustc --explain E0369` to see a detailed explanation
src/main.rs:3:15: 3:28 note: an implementation of `std::ops::Add` might be missing for `&str`
src/main.rs:3 let string = &*vector[0].0 + &*vector[0].1;
^~~~~~~~~~~~~
我已用盡了所有我能想到的組合的。我在這裏錯過了什麼?
'vector [0] .0 +&vector [0] .1',但它將移出'vector [0] .0' –