Smart Pointers in Rust - Interior Mutability

  Рет қаралды 41,495

Let's Get Rusty

Let's Get Rusty

Күн бұрын

The ultimate Rust lang tutorial. Follow along as we go through the Rust lang book chapter by chapter.
📝 Get notified when the Rust Cheatsheet comes out: letsgetrusty.com/
The Rust book: doc.rust-lang.org/stable/book/​​
Chapters:
0:00​ Intro
1:09 Enforcing Borrowing Rules at Runtime
3:36 Interior Mutability Pattern
5:31 Interior Mutability: Mock Objects
13:00 Borrowing Rules with RefCell
14:07 Combining Rc and RefCell
16:41 Outro
#letsgetrusty​​ #rust​lang​ #tutorial

Пікірлер: 44
@letsgetrusty
@letsgetrusty 3 жыл бұрын
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
@arisweedler4703
@arisweedler4703 2 жыл бұрын
Great stuff. Broken down so simply. Rust is fantastic. This is the type of stuff that C’s syntax lets your burn yourself on so easily. And this C++ was forced to lemming after it. The verbosity of syntax around this is a feature, and it makes your wonderful explanation as simple as just reading the code. Great language, great channel, great content! Thanks for saving me tons of time :D
@brianteague8031
@brianteague8031 2 жыл бұрын
Borrow checking at runtime? I feel like if I have to use RefCell, there is something wrong with my design pattern.
@nicholasmanson8615
@nicholasmanson8615 2 жыл бұрын
Or you just need a one off workaround you know won't fail and don't want to rewrite when a simple tool for the situation was already provided by rust staff. Otherwise though mostly yeah
@julianferres
@julianferres 2 жыл бұрын
usize adapts to u32 or u64, depending on the architecture of the computer (32/64 bits). It's more "portable" to write it this way.
@alvaroefmota
@alvaroefmota Жыл бұрын
very interesting
@SharunKumar
@SharunKumar Жыл бұрын
Wouldn't this cause non-deterministic behavior like different overflow limits based on the target system 🤔
@TylerLarson
@TylerLarson 6 ай бұрын
​@@SharunKumar the idea is that your app's business logic already guarantees you won't overflow either value, and you just want the efficiency of using whatever type is native to your architecture.
@markmcdonnell
@markmcdonnell 2 жыл бұрын
Another super useful and enlightening video. Great work as always. Thank you!
@jakubwojciech1
@jakubwojciech1 3 жыл бұрын
Hi Bogdan, thank you very much for all your videos !!! keep doing it, they are great!
@technoflask4525
@technoflask4525 3 күн бұрын
Great Video.💕 But just one suggestion. You should use Cell instead of RefCell in the Cons-list example. As i32 is a copy type, Cell is a better choice as it doesn't have a runtime overhead like RefCell. I feel like for copy types RefCell is an overkill.
Жыл бұрын
Excellent video. It's all about combining.
@herrxerex8484
@herrxerex8484 3 жыл бұрын
Was waiting for this , keep it up bogdan!
@thegeniusfool
@thegeniusfool 3 ай бұрын
The Halting Problem…. That was quite a curve ball in this context. Nice
@sagnikbhattacharya1202
@sagnikbhattacharya1202 3 жыл бұрын
Amazing video as always :D
@exoticcoder5365
@exoticcoder5365 2 жыл бұрын
Very useful Thanks !
@GolangDojo
@GolangDojo 3 жыл бұрын
Fresh cut bro
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 3 жыл бұрын
Next one Cell? 😉
@bjugdbjk
@bjugdbjk 2 жыл бұрын
I just wanna smash the like button infinite times bro !! Fantastic content 👍 need more rusty stuff
@murugarajuperumalla5508
@murugarajuperumalla5508 2 жыл бұрын
go go Rusty
@kampkrieger
@kampkrieger Жыл бұрын
Great! But how can I handle the Panic and go on with my program?
@jjpp1993
@jjpp1993 7 ай бұрын
sooo to know how to read the book
@Galakyllz
@Galakyllz Жыл бұрын
Should we use smart pointers or is this an indication that we need to restructure our code? My question comes down to "Is this a cheat or bandaid for a problem with our project's architecture?"
@durnsidh6483
@durnsidh6483 Жыл бұрын
Unless you're using raw pointers, some type of smart pointer is necessary to put values on the heap which is needed if you don't know how much memory you need to allocate for an object at runtime. That being said, I don't like interior mutability that much and it's a good idea to see if you can refactor your code first.
@jonforhan9196
@jonforhan9196 Жыл бұрын
Multi threading is almost impossible without async ref counting
@codeultima2386
@codeultima2386 3 жыл бұрын
great easy to understand, can you do the Fearless concurrency chapter? thanks
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Yes I will!
@soft384
@soft384 3 жыл бұрын
I think IAM getting rusty!!
@julkiewicz
@julkiewicz Күн бұрын
Hmm, how is that manual ref counting actually better than something like a read write smart pointer in C++? It doesn't really check anything at compile time, so it's all runtime. And if it's all runtime it can still just panic. Which is functionally same as using a weak_ptr etc. Seems like there should be some very strong rules of thumb about when to use that. If I just sprincle RefCell all over the place, it seems to defeat the point of the language.
@CompletelyCovered3
@CompletelyCovered3 3 жыл бұрын
Help! I am trying to write macros! A macro series would be great! 😁
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Coming soon!
@CompletelyCovered3
@CompletelyCovered3 3 жыл бұрын
@@letsgetrusty Thank you so much. You are, in deed, converting a Gopher. Go's great, and I'll continue to use it. But at some point, the simplicity is limiting.
@myronkipa2530
@myronkipa2530 2 жыл бұрын
Could this be abstracted somehow? Seems unnecessarily complicated
@krtirtho
@krtirtho 3 жыл бұрын
Smart Pointers in Rust are like shortcuts to avoid reference errors
@homelikebrick42
@homelikebrick42 3 жыл бұрын
What is your vscode setup?
@letsgetrusty
@letsgetrusty 3 жыл бұрын
it's very basic. I just use rust-analyzer and tabnine.
@DrIngo1980
@DrIngo1980 3 жыл бұрын
@@letsgetrusty I bet that question will come up more often in the future and people do not necessarily read all the comments or your replies. So my suggestion for a quick win: make a short video. Doesn't have to be longer than 5 minutes, just to explain your dev setup. People will appreciate it. And it will make it easy for you in the future to just link to it. If your setup ever changes, great. Another opportunity for yet another video 😊 (This is just a suggestion. Feel free to ignore.)
@NonsensGaming
@NonsensGaming Жыл бұрын
remember kids use Cell instead of RefCell for primitives that implement copy not a big fan of the Rc and RefCell example
@cerulity32k
@cerulity32k Жыл бұрын
i think ill call them smointers
@yassinmoussaoui3323
@yassinmoussaoui3323 2 жыл бұрын
huh
@aaron6807
@aaron6807 Жыл бұрын
This seems pretty unsafe
@32zim32
@32zim32 Жыл бұрын
I think RUST is safe is the biggest misconception of all times. If there are tons of RefCell, Arc, Rc and others, all of them can panic at runtime. So I really can not understand how this can be called a safe language
@fiddle_n
@fiddle_n Жыл бұрын
⁠@@32zim32Any language can panic at runtime. When people say Rust is safe, they are referring to MEMORY safety. Using Rc and RefCell may cause your code to panic but it won’t cause your program to have undefined behaviour
@jeffg4686
@jeffg4686 2 жыл бұрын
Good tutorial, but it looks like copy types got dissed
Smart Pointers in Rust - Reference Cycles
15:38
Let's Get Rusty
Рет қаралды 20 М.
Rust Modules - Explained Like I'm 5
19:59
Let's Get Rusty
Рет қаралды 70 М.
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 6 МЛН
Async Rust Is The Bane Of My Existence | Prime Reacts
35:36
ThePrimeTime
Рет қаралды 96 М.
The Box Smart Pointer in Rust
12:18
Let's Get Rusty
Рет қаралды 69 М.
Self-referential structs (in Rust)
27:21
fasterthanlime
Рет қаралды 52 М.
Closures in Rust
19:53
Let's Get Rusty
Рет қаралды 75 М.
Rust Lifetimes Finally Explained!
19:10
Let's Get Rusty
Рет қаралды 153 М.
Rc and RefCell Smart Pointers - Rust
26:03
danlogs
Рет қаралды 7 М.
8 Design Patterns | Prime Reacts
22:10
ThePrimeTime
Рет қаралды 397 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 140 М.
Arc instead of Vec? | Prime Reacts
37:18
ThePrimeTime
Рет қаралды 64 М.
Box / Rc / Arc / Mutex - Smart Pointers Simplified - Rust
23:39
Bocksdin Coding
Рет қаралды 11 М.
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 8 МЛН
Лучший браузер!
0:27
Honey Montana
Рет қаралды 868 М.
Samsung laughing on iPhone #techbyakram
0:12
Tech by Akram
Рет қаралды 6 МЛН