Is the use of interior mutability part of an interface?

⚓ Rust    📅 2026-03-01    👤 surdeus    👁️ 7      

surdeus

Warning

This post was published 49 days ago. The information described in this article may have changed.

Is it correct to say that when defining a trait/interface, you must decide whether implementers will use interior mutability? In other words, its use is not merely an implementation detail?

When I first learned about interior mutability, I thought it was an implementation detail. However, as I experiment with it, I see that you need to decide whether the trait methods take &self or &mut self, and whether you pass around dynamic objects as Rc<dyn T> or Rc<RefCell<dyn T>> (or their multithread equivalents).

5 posts - 3 participants

Read full topic

🏷️ Rust_feed