Я хочу сравнить два указателя в цикле:
#[derive(Debug)]
struct Test {
first: i32,
second: i32
}
fn main() {
let test = vec![Test{first:1, second:2}, Test{first:3, second:4}, Test{first:5, second:6}];
for item in test.iter() {
println!("--- {:?}", item);
println!("item {:p}", item);
println!("test.last().unwrap() {:p}", test.last().unwrap());
//if item == test.last().unwrap() {
// println!("Last item!");
//}
}
}
println дает мне оба одинаковых адреса
--- Test { first: 1, second: 2 }
item 0x563caaf3bb40
test.last().unwrap() 0x563caaf3bb50
--- Test { first: 3, second: 4 }
item 0x563caaf3bb48
test.last().unwrap() 0x563caaf3bb50
--- Test { first: 5, second: 6 }
item 0x563caaf3bb50
test.last().unwrap() 0x563caaf3bb50
Но когда я комментирую в условии if,выдается следующая ошибка:
error[E0369]: binary operation `==` cannot be applied to type `&Test`
--> src/main.rs:20:17
|
20 | if item == test.last().unwrap() {
| ---- ^^ -------------------- &Test
| |
| &Test
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `&Test`
Как сравнить только два указателя?