What is the point of using cell since mutable reference can be obtained using Rc::get_mut?

Be very careful when you use unsafe. If you viloate the compiler constraints against concurrent mutable access, you create UB. That can permit the LLVM backend to mis-compile (by your definition) your program, because you have lied to the compiler that you have upheld LLVM's constraints even when you have not. LLVM is not out to get you; it is just optimizing the hell out of your program based on your promise that you have not violated its constraints. The rustc frontend normally enforces those constraints via the borrow checker and other mechanisms, but unsafe lets you take over that enforcement responsibiity. If you screw up, don't expect the resultant binary to be actually correct, even if it appears to work in the short term.


In my case It is guaranteed to run in a single thread context otherwise I would have used Arc<RwLock> to ensure safety but in a very small single threaded block it really seems a bit overkill to go through Rc<Cell>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.