Crust of Rust: Smart Pointers and Interior Mutability
Channel: Jon Gjengset
Date: 2020-06-18

In this fourth Crust of Rust video, we cover smart pointers and interior mutability, by re-implementing the Cell, RefCell, and Rc types from the standard library. As part of that, we cover when those types are useful, how they work, and what the equivalent thread-safe versions of these types are. In the process, we go over some of the finer details of Rust's ownership model, and the UnsafeCell type. We also dive briefly into the Drop Check rabbit hole (https://doc.rust-lang.org/nightly/nomicon/dropck.html) before coming back up for air.

This is definitely a more technically advanced stream than some of the earlier ones, and may be a little harder to follow. I apologize for that in advance! Please do leave questions here or on Discord and I'll try to help explain what's going on.

You can find the final code at https://gist.github.com/jonhoo/7cfdfe581e5108b79c2a4e9fbde38de8 and the Discord at https://discord.gg/RJdqQ9n

0:00:00 Introduction
0:01:11 Discord
0:02:31 Agenda
0:03:50 Interior Mutability
0:07:47 Cell
0:23:39 Trying to Test Cell
0:40:17 UnsafeCell
0:41:21 RefCell
0:54:21 RefCell Smart Pointer
1:06:27 Rc (reference counted ptr)
1:23:49 NonNull
1:31:55 PhantomData and Drop Check
1:44:25 ?Sized Briefly
1:47:30 Thread Safety
1:54:20 Copy-on-Write (Cow)

You can watch the live version with comments at https://www.youtube.com/watch?v=1e5aDptlGoI