Rust: RefCell

Опубликовано: 29 Декабрь 2022
на канале: The Dev Method
8,697
226

#rust #refcell #interiormutability

Interior Mutability - Mutate the data even with immutable references to that data. The borrowing rules disallow this in Rust. RefCell follows this Interior Mutability Pattern.

0:00 intro
1:16 Enforcing Borrowing Rules at Runtime with RefCell
4:25 Interior Mutability: A Mutable Borrow to an Immutable Value
5:01 A Use Case for Interior Mutability: Mock Objects
9:04 Keeping Track of Borrows at Runtime with RefCell
16:55 Having Multiple Owners of Mutable Data by Combining Rc and RefCell
19:25 Outro

Links

Unsafe Rust
https://doc.rust-lang.org/book/ch19-0...

RefCell borrow_mut
https://doc.rust-lang.org/std/cell/st...

RefMut implements Deref
https://doc.rust-lang.org/src/core/ce...

Mutex
https://doc.rust-lang.org/book/ch16-0...