While doing the Rust track in Exercism, I came accross the singly linked list exercise. Once my compilation passed the tests, I continued to work on the code to add some more functionality and train myself.
The error I get while compiling is error[E0369]: binary operation == cannot be applied to type T
pub fn find(&self, value: T) -> bool {
let mut head = self.head.borrow();
while let Some(node) = head {
match node.next {
None => return false,
Some(a) => {if a.data == value { return true }},
}
head = &node.next;
}
false
}
The error happens when comparing a.data with value.
I thought that the PartialEq implementation for Node should take care of that.
If possible, I would like some assistance in that matter.
error[E0599]: no method named `borrow` found for enum `std::option::Option<std::boxed::Box<Node<T>>>` in the current scope
--> src/lib.rs:30:34
|
30 | let mut head = self.head.borrow();
| ^^^^^^ method not found in `std::option::Option<std::boxed::Box<Node<T>>>`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
1 | use std::borrow::Borrow;
|
Thanks, but those are only there due to the change in the find function from the two versions I sent. That's my fault.
But still, the error I mentioned in the post about comparing T values is still there. Playground