refcell

How can I implement Deref for a struct that holds an Rc<Refcell<Trait>>?

核能气质少年 提交于 2020-03-02 09:26:31
问题 My goal is to delegate method calls against my struct to a Trait's methods, where the Trait object is inside an Rc of RefCell . I tried to follow the advice from this question: How can I obtain an &A reference from a Rc<RefCell<A>>? I get a compile error. use std::rc::Rc; use std::cell::RefCell; use std::fmt::*; use std::ops::Deref; pub struct ShyObject { pub association: Rc<RefCell<dyn Display>> } impl Deref for ShyObject { type Target = dyn Display; fn deref<'a>(&'a self) -> &(dyn Display +