How to borrow the T from a RefCell<T> as a reference?
问题 Sometimes I have a struct containing a value which is wrapped in a RefCell , and I want to borrow the value, but I don't want to make the signature of the accessor function to depend on the internal implementation. To make it work, I need to return the reference as a Ref<T> instead of a &T . For example, if this is my struct: use std::cell::RefCell; pub struct Outer<T> { inner: RefCell<T>, } I could write an accessor like this: use std::cell::Ref; impl<T> Outer<T> { fn get_inner_ref(&self) ->