Is that a case for interior mutability needs?

Hi again,

I'm trying to combine two crates and the API seems quite incompatible to me:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0f33a92b49a9a1745bda1ff5e3d8f798

reg_fct only gives me &self but I need to call operation which needs &mut self. I though that might be the place to use a Cell but I can't make it compile with a Cell neither.

What am I missing here?

Cell doesn't let you get a reference to it's internals, so you will need to take Connection out of the Cell temporarily, and then call operation, then you can put it back in the Cell (but this may be difficult to do). Another way to do this is using RefCell, which may be easier to use because it does give you direct access to it's wrapped value.

Cell: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=58c540670ee1876b1f6aa190057e89aa
RefCell: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=caf67bcbdd55aeb0908c95880a894740

1 Like

Thanks a lot! I went the RefCell route :slight_smile: