Can use .borrow_mut, but not .borrow, on Rc<RefCell<foo>>

Playground: Rust Playground

Here I can borrow mutably from an Rc, which I don't need, but cannot borrow non-mutably. Puzzled as to why.

It works if you remove the use std::borrow::Borrow; at the top. It's because the <Self as Borrow>::borrow() has higher precedence over the <Self as Deref>::Target::borrow() on the method lookup.

1 Like

Ah. Non-obvious, but it works.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.