Тёмный

Understanding Ownership in Rust 

Let's Get Rusty
Подписаться 118 тыс.
Просмотров 242 тыс.
50% 1

The ultimate Rust lang tutorial. Follow along as we go through the Rust lang book chapter by chapter.
📝 Get your FREE Rust Cheatsheet: www.letsgetrusty.com/cheatsheet
The Rust book: doc.rust-lang.org/stable/book/​
Stack & Heap explanation: • Pointers and dynamic m...
0:00 Intro
0:40 Ownership Model
4:30 Stack & Heap
6:53 Ownership Rules
7:21 Variable Scope
8:22 Memory & Allocation
10:32 Ownership & Functions
12:23 References & Borrowing
18:34 The Slice Type
24:56 Outro
#letsgetrusty​ #rust​lang #tutorial

Наука

Опубликовано:

 

25 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 299   
@letsgetrusty
@letsgetrusty 3 года назад
📝Get your *FREE Rust Cheatsheet* : www.letsgetrusty.com/cheatsheet
@enderger5308
@enderger5308 3 года назад
I don’t know why, but the borrow checker doesn’t confuse me that much. Use a reference when you want to see the original memory through a window, move when you want the data for yourself, and never have a window to a place that does not exist.
@letsgetrusty
@letsgetrusty 3 года назад
You are one of the chosen.
@ddastoor
@ddastoor 3 года назад
a good example from soft engg is to compare the ownership model with read-write lock semantics...
@inx1819
@inx1819 3 года назад
The basics of borrow checking isn't hard, but sometimes it can get tricky and very confusing in complicated code
@comradedownpressor1218
@comradedownpressor1218 3 года назад
This is the best concise explanation of borrowing I've seen yet
@OggerFN
@OggerFN 2 года назад
@@ddastoor because it's about the same problem
@eileennoonan771
@eileennoonan771 6 месяцев назад
I am going to watch this every day until I understand it in my bones
@king_james_official
@king_james_official Месяц назад
REAL
@tullochgorum6323
@tullochgorum6323 2 года назад
As a line-of-business developer I've been a bit intimidated about learning an innovative system language like Rust - but this makes one of the gnarliest features seem learnable. You're a good teacher.
@stardustbiscuits
@stardustbiscuits 2 года назад
Wait until u learn traits
@tonybelonog2941
@tonybelonog2941 Месяц назад
@@stardustbiscuits so crazy true
@nathanielwoodbury2692
@nathanielwoodbury2692 3 года назад
You're an incredible teacher, so much clarity.
@islapthebass
@islapthebass 2 года назад
He doesn't derail ever, seamless additive commentary, and an enjoyable voice haha
@carloslfu
@carloslfu 2 года назад
+1
@kayakMike1000
@kayakMike1000 Год назад
Most of what he said about stacks and heaps was misleading enough that I don't think he really understands it very well.
@-karter-4556
@-karter-4556 11 месяцев назад
Basically just summarizing the book
@playfulyogi5639
@playfulyogi5639 10 месяцев назад
@@-karter-4556 almost word for word plagiarism
@desrucca
@desrucca 2 года назад
Finally, found someone that covers the rust guide book. Thanks, man. Super time saver
@letsgetrusty
@letsgetrusty 2 года назад
Glad I could help!
@jesusmtz29
@jesusmtz29 Год назад
im amazed at how much the rust-analyzer and compiler are teaching me without even running code. You're explanation makes it a top-grade experience
@giovannimazzocco499
@giovannimazzocco499 2 года назад
This is by far the best explanation about Rust's borrow mechanism I've encountered so far! The course is an excellent resource for Rust newcomers. Great work!
@SKyrim190
@SKyrim190 2 года назад
I think that was the best explanation I've come across so far...you took the time a noobie would need to learn this stuff, and didn't try to "keep under two minutes" destroying the clarity for the sake of speed. Also, you didn't jump immediately to metaphors of "oh, its like if you have a book, and you lend it to someone, but that person can write on the book" and so on...I also find those unnecessary and confusing sometimes
@teenspirit1
@teenspirit1 Год назад
7:57 - why would you have to use new to allocate memory on the heap in C++? Just use std::string s("hello"), or std::vector and it works just like it did since 30 something years, memory is deallocated at the end of scope.
@fennecfox2366
@fennecfox2366 10 месяцев назад
True, you don't have to manage the memory yourself with raii data structures. Be aware these data structures are still doing dynamic allocation, but they are doing it in a safe way. You still take a potential performance hit but memory leaks shouldn't be an issue.
@fennecfox2366
@fennecfox2366 10 месяцев назад
You can use a std::array if you want to avoid the free store and use automatic(commonly referred to as stack) storage. Std::array requires a size known at compile time.
@Haitaish
@Haitaish Год назад
10:53 "When we pass in parameters into a function its the same as if we were to assign s into another variable" - now that's when the borrow checker finally clicked for me. Now I also understand why it's so controversial to some people. Your tutorial so clear and easy to understand. Thank you!
@scheimong
@scheimong 2 года назад
Wish I had this video last year when I was learning Rust. You explained the concepts fantastically.
@agustindeluca2304
@agustindeluca2304 2 года назад
Mindblowing 🤯🤯🤯 Thank you so much for your dedication. You're an incredible teacher!
@aaronkingcto
@aaronkingcto Год назад
This is really fantastic! Your cadence, examples and explanations are really great! I've been programming for 25 years (C++, C#, Js, etc etc) and this is a really nice way to understand nuances of rust. Thank you!
@kayakMike1000
@kayakMike1000 Год назад
25 years and this rank amateur explains things well? What? Are you one of those php script monkeys? It was awful.
@bobbybob628
@bobbybob628 2 года назад
The very best channel for Rust learners that I have found so far! Thank you, buddy! Wish you all the best and prosperity to your channel!
@eslamelsharkawy9660
@eslamelsharkawy9660 Год назад
I think this is the best video on RU-vid to explain the ownership model. Great Work.
@samdavepollard
@samdavepollard Год назад
Very nice series As a hobbyist who's dabbled in a bunch of languages because it's fun, i'm now learning me some rust. Certainly doing my share of fighting with the borrow checker but that said, i'm super impressed with the errors and warnings that the compiler spits out. Most helpful messages that i've encountered in any language; have helped me sort out a bunch of things which in other languages i would have had to fire up the google to work out what was going on.
@martynclarke8400
@martynclarke8400 Год назад
Honestly man, your videos have really helped me whilst I go through the book. Theres a lot of information to consume so appreciate you taking the time to make these accompanying videos (y), some things are easier to see than to read and vice versa :)
@yichizhang5707
@yichizhang5707 3 года назад
I read the rust book ownership chapter but was confused. Your video makes the concept much clearer. Thanks and keep it up!
@biocuts
@biocuts 2 года назад
You explained it in a very concise and clear way. Good job!
@kmaximoff
@kmaximoff 3 месяца назад
I was worried learning Rust, but more I look at this. THIS MAKES SO MUCH SENSE!
@andythedishwasher1117
@andythedishwasher1117 Год назад
So I recently just made my first foray into Rust by attempting to build a calculator in a Yew app. I am still struggling with the logic itself, but I actually found the battle with the borrow checker to be one of the more refreshing sorts of problems I ran into. It made me think so much harder about where I was declaring my variables and where I was mutating them that it kinda just felt like my brain was steadily increasing in mass and wrinkle count the whole time.
@kellyrankin8844
@kellyrankin8844 Год назад
this is how I sort of interpreted it.."stop doing these things unless you really need to because they're just problematic"
@Antonio-ix3fw
@Antonio-ix3fw Год назад
I have just started learning Rust and your videos are helping me to understand all the tricky Rust concepts. Thanks! .
@bigtymer4862
@bigtymer4862 3 года назад
Going through the rust book right now... very helpful!
@adamtak3128
@adamtak3128 3 года назад
Really good video. I'll be coming back to this over and over until it's stuck in my memory.
@WarrenMarshallBiz
@WarrenMarshallBiz Год назад
This channel is pure gold, thanks man!
@twentyeightO1
@twentyeightO1 Год назад
Man I'm getting all worked up converting my c++ program to rust. 2 days in and I am no where near to finish it. Now I've realized that my "c++ way of thinking" is getting in the way.
@TheKisem
@TheKisem Год назад
First tutorial series on RU-vid where I don't even hesitate for a second before clicking the thumbs up button. Great job!
@TheSkepticSkwerl
@TheSkepticSkwerl Год назад
i took an online course, it was short but still, it explained Strings and string slices. (literals) etc... but the way you explained them in this video were so much more clear. thank you.
@rusty9060
@rusty9060 2 года назад
17:16 is such an elegant info. I love how they designed Rust language
@almuaz
@almuaz 7 месяцев назад
I read the book and i was overwhelmed of new terms and information. this video helped me to visualize it live. yes rust book visualizations were great but for me i find this more helpful. i think after watching this, i will understand the book better. thank you. there are too little learning resources for rust :)
Год назад
what a great explanation I was so confused now that I decided to learn the language and you made it all clear for me in 25min YOU ROCKS! thx from 🇧🇷
@exoticcoder5365
@exoticcoder5365 3 года назад
good work ! I understand a lot ! can't wait to see more Rust content !
@MCGreen13
@MCGreen13 Год назад
This was the best outline of this topic that I’ve seen. Thank you.
@user-qr4jf4tv2x
@user-qr4jf4tv2x 11 месяцев назад
the reference and borrow is definingly the best part of this tutorial
@TheOriginalJohnDoe
@TheOriginalJohnDoe 2 года назад
You sir... are an incredible teacher and have just got a new subscriber!
@Souljacker7
@Souljacker7 Год назад
I was struggling understanding Steve Klabnik's and Carol Nichols' book, but you made it perfectly clear. Thanks!
@rishkum536
@rishkum536 2 года назад
Beautiful video bro. Thanks for creating this. I understand what is so special about Rust now
@opticonor
@opticonor Год назад
Great vid, looking forward to watching the rest of them!
@nowarm
@nowarm 18 дней назад
Thank you for making this. It's so helpful and so easy to follow along. You're amazing
@dixztube
@dixztube 10 месяцев назад
I work with node and go for my serious business projects but I did get a offer from a firm that uses rust and pretty flexible timeline if I ever wanted to onboard. This got me into going through the rust book and learning the language… I really like it! I also liked go a lot too.. probably because I started in insane crazy js land now these relatively new languages seem to nice
@sukarnarut
@sukarnarut Год назад
Awesome teaching. The pace is very good and information goes straight into my brain with good understanding of the concept.
@ostap418
@ostap418 2 года назад
Thank you so much, I am learning rust after java and javascript background, and it's quit tough. But your videos help a lot! Thank you
@abdullahfurkanozbek7558
@abdullahfurkanozbek7558 Год назад
Perfect explanation, even though the concept is hard to understand, the explanations and examples provided in this video are very valuable. Thank you for it.
@michaeljburt
@michaeljburt 2 месяца назад
Right around 14:10 was the lightbulb moment for me. And being a long time C and C++ programmer I think I'm finally starting to see why this Rust thing makes sense... What a clever way to make sure that we know who is writing data and who is just reading or calling getters. It makes the C/C++ way of using references, pointers and const seem kind of silly.
@garotalibertaria7219
@garotalibertaria7219 Год назад
Best explanation about ownership and borrowing, it helped me a lot.
@Tobi-gl2lb
@Tobi-gl2lb Год назад
Thanks a lot for this series. Very good explained.
@-karter-4556
@-karter-4556 11 месяцев назад
I wish I found this language sooner 😫. The control and defined, predictable behavior is so appealing.
@muthuisheree
@muthuisheree Год назад
Thank you for the wonderful explanation. Extremely valuable
@sundaymanali5854
@sundaymanali5854 2 года назад
10:53 gold info here. love this channel
@finkelkop7204
@finkelkop7204 Год назад
Realy good explanation. TY!
@alfredomenezes8814
@alfredomenezes8814 2 года назад
This lesson was amazing, thank you very much 🦀❤️
@AndrewLighten
@AndrewLighten 3 месяца назад
Brilliant explanation. Thank you.
@sahilverma4077
@sahilverma4077 3 года назад
awsome explanation, keep up the good work
@tahsinulhaqueabir1046
@tahsinulhaqueabir1046 Год назад
Best video on rust ownership
@avisalon4730
@avisalon4730 2 года назад
Thanks! Very understandable video. Easy to learn.
@user-bu3hz5be5w
@user-bu3hz5be5w Год назад
Thanks! Very good explanation!
@MrSerler
@MrSerler Год назад
thank you so much. great tutorial.
@nikhilsinha2191
@nikhilsinha2191 Год назад
I have watched tilll 17:19 and can say the explanation is top notch took me 45 min to react this point as I am coding as well the information which I find useful will continue from here the next day
@glebirovich4519
@glebirovich4519 3 года назад
Hey mate! Keep going! Very well explained.
@letsgetrusty
@letsgetrusty 3 года назад
Thanks Gleb!
@rizaldi4563
@rizaldi4563 3 года назад
Omg! Thankyou so much!!!
@hamzadlm6625
@hamzadlm6625 Год назад
I love u, thanks for the clear explanation
@MrPflanzmann
@MrPflanzmann 2 года назад
I love this videos. Great work!
@aleksandrbakhmach9810
@aleksandrbakhmach9810 2 года назад
Awesome, thanks man!
@fennecfox2366
@fennecfox2366 10 месяцев назад
Coming from c++ this is intuitive. Unique pointers and move semantics give this type of behavior as options in modern c++ so having them as the default makes sense. Also having the const as default on refs is another good safety measure. I do think a basic understanding of pointers in c and references and smart pointers in c++ will help people understandownership and the ideas it's built upon.
@connorzittrauer3306
@connorzittrauer3306 2 года назад
This video was great. Thank you 👍
@_pro_grammer_
@_pro_grammer_ 5 месяцев назад
finally learning rust 💙
@MultiKB13
@MultiKB13 2 года назад
This video is incredible, I can’t believe you don’t have more subs
@ChrisHalden007
@ChrisHalden007 Год назад
Great video. Thanks
@hanshaun1350
@hanshaun1350 9 месяцев назад
This is BY FAR the hardest part to learn Rust. It's frustrating to learn without any C background tbh.
@kqvanity
@kqvanity 2 месяца назад
I genuinely don't understand that claim. I might get that you'd 'appreciate it more' not having to deal with either garbage collection/erroneous manual memory management, but not having C/C++ being a prerequisite to learn rust
@workflowinmind
@workflowinmind 2 года назад
I needed this! Thanks
@LuisMateoAriasCaicedo
@LuisMateoAriasCaicedo 3 месяца назад
Thank you very much!
@sentimentalbaboon4262
@sentimentalbaboon4262 2 года назад
Great video, thank you!
@hansrudolf5849
@hansrudolf5849 Год назад
Great job!
@codelearner4449
@codelearner4449 Год назад
You're an amazing teacher thanks man. The way you expained how rust stops two mutable references in the same scope to prevent race conditions. If I am not wrong, this feature isnt there in golang, and this is where rust outshines. This feature will outshine even more, when concurrency comes into play. Explaining why rust promotes safe concurrency. Correct me if I got this right.
@googleuser2016
@googleuser2016 2 года назад
Great tutorial!
@marlonou8818
@marlonou8818 2 года назад
Save me time reading thru the chapter myself 😄
@_jirkaa_5170
@_jirkaa_5170 Год назад
When I watched 2 hour tutorial for rust and was completly confused but now its like really easy
@Asgallu
@Asgallu 2 года назад
Great video!
@_jdfx
@_jdfx 2 года назад
Still a great video! thank you!
@srinivasvalekar9904
@srinivasvalekar9904 3 года назад
*Me* : Casually starts to watch video to understand closures After sometime , Can't stop watching other videos. I was so deeply involved in listening your videos, I noticed a background music, could you please tell me which song it is :D
@foobar1269
@foobar1269 2 года назад
Thank you for explaining stack and heap. Now Rust makes more sense in terms of making some of the code design pattern decisions.
@bitfluent
@bitfluent Год назад
Idk who invented the borrowing/ownership concept, but it's genius.
@ronny332
@ronny332 5 месяцев назад
What I really like about your videos, until now :-), is the speed, you tell things. I'm not native American or English, but most every tutorial I watched for instance on Udemy was so slow. Of cause someone can speedup the video, but sometimes, the speaker speaks faster or changes slides, and that results in confusion. Very, very well done, again until here 🙂as I don't know more of your videos besides the seen ones.
@Muslim_qui_doute
@Muslim_qui_doute 2 года назад
FINALLY SOMEONE WHO DO STUFF IN CODE INSTEAD OF TALKING IN AIR :D
@asjn3e
@asjn3e 2 года назад
for my new job i have to learn rust fast and i'm not really good at reading documentations and books so thank you for great and useful videos
@GlobalYoung7
@GlobalYoung7 2 года назад
Thank you. 😀🥳
@bzzzvzzze
@bzzzvzzze Год назад
great video!
@uovo
@uovo Год назад
You are a machine gun of free and high quality knowledge wow
@ddastoor
@ddastoor 3 года назад
great video buddy.
@sheikhakbar2067
@sheikhakbar2067 3 года назад
Thanks a lot.
@letsgetrusty
@letsgetrusty 3 года назад
Most welcome!
@ksnyou
@ksnyou 3 года назад
good explanation
@robsaunders9681
@robsaunders9681 Год назад
(Garbage,manual,ownership) all three are ways to free memory. Garbage collection means automatic memory management. The ownership-model is garbage collection on code pre-constrained by the borrow checker.
@cryptomando
@cryptomando 2 года назад
Great video
@Christobanistan
@Christobanistan 2 месяца назад
This is by far the toughest part of Rust. I really wish the book had a ton more examples and explained things far better.
@snk-js
@snk-js 2 года назад
wonderful!
@HarshRajput-jr7qp
@HarshRajput-jr7qp Год назад
great video bro
@zb2747
@zb2747 2 года назад
Man thank you - I have to use rust for a project and learning rust through the docs/book along with your video course has helped me a lot! You explain things really well and at a nice talking pace with examples and implementation - thanks bro!
@quangle5701
@quangle5701 3 года назад
Thanks for the video. I would like to know how to apply the slice and ownership for the array of String objects (not &str), especially when passing them to a function as arguments ? Thanks
@ErikBongers
@ErikBongers 2 года назад
I do feel you should add an asterisk behind "Slower write time" for the Ownership Model. For a beginner it's definitely (frustratingly) slower as, indeed, you have to fight the borrow checker. But I would thing that a very experienced Rust programmer "dances" with the borrow checker rather that fight with it. As a result, the struggle will be neglectable. Such a programmer will find it slower to write similar code with the same robustness in C or C++ as he would suddenly have to to worry about all the leaks and race issues.
@itellyouforfree7238
@itellyouforfree7238 Год назад
also "slower write time" is extremely misleading. if would take the exact same time in C/C++ to write the exact same safe code. on the other hand, what you can code in less time in C/C++ is probably WRONG and riddled with bugs
Далее
Structs in Rust
17:22
Просмотров 99 тыс.
Strings in Rust FINALLY EXPLAINED!
21:40
Просмотров 74 тыс.
🥔 Sloppy Joe Potato Casserole ~#Shorts
00:23
Просмотров 4,2 млн
All Rust features explained
21:30
Просмотров 286 тыс.
but what is 'a lifetime?
12:20
Просмотров 60 тыс.
Intro to async/.await in Rust
13:57
Просмотров 83 тыс.
I spent six months rewriting everything in Rust
15:11
Просмотров 408 тыс.
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
Rust Demystified 🪄 Simplifying The Toughest Parts
14:05
Rust Ownership and Borrowing
38:21
Просмотров 66 тыс.
WHY IS THE STACK SO FAST?
13:46
Просмотров 137 тыс.
Common Programming Concepts in Rust
14:33
Просмотров 93 тыс.