I have the following definition:
pub struct List<T> {
memory: Vec<T>,
}
I would get the equivalent of #[derive(PartialEq)]
for this type like describe in How can I implement PartialEq?
I use a match expression, like:
impl<T: PartialEq> PartialEq for List<T> {
fn eq(&self, other: &List<T>) -> bool {
self.memory == other.memory
}
}
impl<T: fmt::Debug> fmt::Debug for List<T> where T:Display {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "["));
for (count, v) in self.memory.iter().enumerate() {
if count != 0 { try!(write!(f, ", ")); }
try!(write!(f, "{}", v));
}
write!(f, "]")
}
}
impl<T> List<T> {
pub fn new() -> Self {
List {
memory: Vec::new(),
}
}
// push() add to end of list
pub fn push(&mut self, value: T) {
self.memory.push(value);
}
}
But the compiler gives me these errors:
error: mismatched types [E0308]
if ! ( * left_val == * right_val ) {
note: in this expansion of assert_eq!
help: run
rustc --explain E0308
to see a detailed explanationnote: expected type
librusty_data_structures::List<u32>
note: found type
[_; 4]
main.rs that produce compile errors
let mut listex: List<u32> = List::new();
listex.push(17);
listex.push(18);
listex.push(19);
listex.push(20);
assert_eq!(listex, [17, 18, 19, 20]);
I don't understand why that matters. Why is it even looking at that type?