Hacker News new | ask | show | jobs
by comex 1910 days ago
FWIW, another option is to use `std::cell::Cell`. That only allows replacing the value rather than borrowing it in place, so you would have to take the value out and put it back after you're done with it, which also results in unnecessary code generation. But there'd be no branch and no panic, so the impact should be less than RefCell. There's also no borrow flag to take up space (not that it really matters when this is a single value on the stack).
1 comments

This is a good point. I always forget Cell can be used with non-Copy types too.