Also worth mentioning is that it's almost always better to use Cell instead of RefCell for Copy types (like i32). This avoids the overhead of the runtime borrow check and can never cause a panic.
Arc, Rc, Box and Cell/RefCell are the most confusing aspects, so far, of my learning Rust. I will have to re-watch your videos a few times, in hopes of grasping these concepts. Thanks!
Unsafe Rust gives you a few "superpowers", but playing jedi mind tricks with the borrow checker is not one of them. The borrow checker will still check your code. :D As far as I remember these types with internal mutability all ultimately use UnsafeCell as a building block. The compiler gives UnsafeCell some special treatment.
because it just checking if it's sending correct message or not in the real world example it will not take mutable reference of a string because we just want send that message via email or number , so we are not storing it and we can't really change our implementation just for test
So why would RefCell be unsafe if it's implemented by the Rust devs? The entire compiler could have bugs that make Rust code fail, so why not give RefCell the same guarantee and call it a safe intrinsic?
Also worth mentioning is that it's almost always better to use Cell instead of RefCell for Copy types (like i32). This avoids the overhead of the runtime borrow check and can never cause a panic.
Arc, Rc, Box and Cell/RefCell are the most confusing aspects, so far, of my learning Rust. I will have to re-watch your videos a few times, in hopes of grasping these concepts. Thanks!
Just wanted to mention you say the the correct definition for Rc but the text is incorrect it should be allow "immutable" checks at compile time @4:09
I've been confused by this but this video explains RefCell/RefMut so clearly! Thanks!
Just worked through this chapter in the rust programming book today, perfect time for your video to appear in my feed for a recap!
Unsafe Rust gives you a few "superpowers", but playing jedi mind tricks with the borrow checker is not one of them. The borrow checker will still check your code. :D
As far as I remember these types with internal mutability all ultimately use UnsafeCell as a building block. The compiler gives UnsafeCell some special treatment.
Nice video, btw 👍
I liked your mock example.
Agreed; the Rustonomicon is pretty clear that you still have to obey the borrowing rules, in some form.
this was helpful. much appreciated!
thank you ❤
Why don't just change the `trait Messenger` signature to `mut self` ?
because it just checking if it's sending correct message or not
in the real world example it will not take mutable reference of a string
because we just want send that message via email or number , so we are not storing it
and we can't really change our implementation just for test
So why would RefCell be unsafe if it's implemented by the Rust devs? The entire compiler could have bugs that make Rust code fail, so why not give RefCell the same guarantee and call it a safe intrinsic?