最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rust - Automatically generate functions that call equivalents inside a Rc<RefCell<_>> encapsulation?

programmeradmin0浏览0评论

With a class which needs to be shared:

struct A;

impl A {
    fn new() -> Self { A }
    fn a(&self) {}
    fn b(&mut self) {}
}

struct AShared(Rc<RefCell<A>>);

is there a way to generate functions which call their inside equivalents? That is, generate some/all of the following:

impl AShared {
    fn new() -> Self { Self(Rc::new(RefCell::new(A::new()))) }
    fn a(&self) { self.0.borrow().a() }
    fn b(&mut self) { self.0.borrow_mut().b() }
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论