I have a structure with a field defined as follows:
log_str: RefCell<String>
I performed various calls to borrow_mut()
to call push_str(.)
on the field. At the end, I'm assessing its value using:
assert_eq!(os.log_str.borrow(), "<expected value>");
Nonetheless, the line of the assert raises a compile-time error with the message:
error[E0369]: binary operation
==
cannot be applied to typestd::cell::Ref<'_, std::string::String>
I understand why the error is happening, since the compiler even hints:
an implementation of
std::cmp::PartialEq
might be missing forstd::cell::Ref<'_, std::string::String>
My question is: how should I compare the value enclosed in a RefCell<T>
(typically in this case, comparing the enclosed string with an expected value).
Thanks !
You want to de-reference the borrow
ed value:
assert_eq!(*os.log_str.borrow(), "<expected value>");