Learning Rust: Memory, Ownership and Borrowing

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

ความคิดเห็น • 144

  • @taylorallred6208
    @taylorallred6208 5 ปีที่แล้ว +101

    That was one of the greatest analogies for teaching scope I have ever seen. Also, thank you for helping me understand rust's ownership!

    • @YouCodeThings
      @YouCodeThings  5 ปีที่แล้ว +2

      Cheers! Glad the video was useful :)

    • @brianhechinger8715
      @brianhechinger8715 ปีที่แล้ว

      I'm only finding this video three years later but I just have to echo this. I've always struggled explaining stack/heap to people and this analogy makes it so super simple. I'm totally stealing this. 😀

  • @itsr4yd946
    @itsr4yd946 5 ปีที่แล้ว +42

    This channel deserves A LOT more subscribers!

  • @wutong4524
    @wutong4524 2 ปีที่แล้ว +1

    Holly crap, this video is golden

  • @YouCodeThings
    @YouCodeThings  6 ปีที่แล้ว +80

    You're an amazing person!

    • @ichdich2332
      @ichdich2332 6 ปีที่แล้ว

      Thank you, dito.

    • @Manja500
      @Manja500 5 ปีที่แล้ว +5

      I can see you haven't made any videos in a while. Please don't give up, your doing great. I know TH-cam channel growth can be slow, but you will get there at some point. Love the videos, keep up the great work.

    • @mikailkhan9166
      @mikailkhan9166 5 ปีที่แล้ว +1

      no u

    • @HermanWillems
      @HermanWillems 4 ปีที่แล้ว +1

      Did you just comment this to your own video? :) haha you must feel amazing about your own personality :D

  • @rifaldhiaw
    @rifaldhiaw 3 ปีที่แล้ว +1

    This is the best borrow system explanation yet!

  • @TBaguette
    @TBaguette 5 ปีที่แล้ว +7

    Please continue making videos, you're clearly one of the funniest and best channels about programming ever ! I'd even say that if one day Rust becomes more popular, your channel could become very successful ! I really enjoy your Rust videos, I hope more are coming soon.

  • @verified_tinker1818
    @verified_tinker1818 3 ปีที่แล้ว +2

    One of the best programming tutorials I've ever seen. Thanks!

  • @nhefner
    @nhefner 2 ปีที่แล้ว +1

    I just started with Rust and this video was super helpful! Keep up the excellent work, you deserve way more subs!

  • @kaderramy4021
    @kaderramy4021 5 ปีที่แล้ว +3

    mind blow. of how easy you make complicated rusty concepts look. keep rocking dude

  • @Sssssssassy
    @Sssssssassy 6 ปีที่แล้ว +2

    I just finished reading the Ownership chapter of the book and this further solidified and clarified the lessons, thank you!

  • @albert21994
    @albert21994 5 ปีที่แล้ว +5

    this is the best programming channel I have discorvered! subbed.

  • @NoorquackerInd
    @NoorquackerInd 4 ปีที่แล้ว +1

    Every TH-cam video about Rust is always at least half an hour long and I've put off learning just because of that, but finally I've found something good

  • @flash_alexander
    @flash_alexander 5 ปีที่แล้ว +6

    I wish to have similar videos covering the entirety of rust? your videos are vivid and make it easy to understand Rust for a programmer

  • @Arunscape
    @Arunscape 6 ปีที่แล้ว +3

    This is the best way I've seen ownership being explained. Thank you!

  • @officialabdulrehman
    @officialabdulrehman 2 ปีที่แล้ว +1

    What a gem of a channel 💎

  • @avimehenwal
    @avimehenwal 5 ปีที่แล้ว +1

    I am having so much fun learning #Rust. Thankyou you guys @YouCodeThings, these videos makes it so effortless. Thats the power of community

  • @interceptings8624
    @interceptings8624 ปีที่แล้ว

    ACTUALLY SUCH A GOOD VIDEO i like the animations and explanations just makes it that much easier from going from something i know to jibberish code

  • @sashalarious5990
    @sashalarious5990 9 หลายเดือนก่อน

    Really enjoying the color scheme of this channel ☺️

  • @nathanielgraham958
    @nathanielgraham958 4 ปีที่แล้ว

    I came across your video while trying to figure out why I got errors no matter where I tried to put an '&'. At the end of the video, I looked at my code, went "huh," and typed a single '&' next to one of my variable calls. Immediately every red squiggly line disappeared. Thank you! You explained ownership in an extremely helpful way.

  • @anshvashisht8519
    @anshvashisht8519 ปีที่แล้ว

    that a wonderful explanation, so much time invested in making the difficult concept clear by animation.

  • @soupnoodles
    @soupnoodles 3 ปีที่แล้ว +1

    Really loved this video, especially the out-of-scope lesson
    Really didn't get into my head just by reading the book, this was super useful!

  • @DeriveIt
    @DeriveIt 8 หลายเดือนก่อน

    This video is great. Love the call stack analogy.

  • @CaptMirage
    @CaptMirage 2 หลายเดือนก่อน

    this is the best explanation i have ever seen, subbed
    oh yea also you dropped this : 👑

  • @fahmi2978
    @fahmi2978 6 ปีที่แล้ว +1

    The Friendly way to Learn Rust , and i love it . Thanks mate

  • @ragrazila
    @ragrazila 4 ปีที่แล้ว

    this channel deserves many more subscribers.

  • @rajanpoudel3787
    @rajanpoudel3787 6 ปีที่แล้ว +2

    subscribing to your channel is the best thing that happen to me. loved your tutorials.

    • @YouCodeThings
      @YouCodeThings  6 ปีที่แล้ว +1

      Thanks for leaving a comment and subscribing!!! :) Your comment is the best thing that's happened to me.

  • @lancecarter8732
    @lancecarter8732 3 ปีที่แล้ว

    Was just reading chp.4 in the Rust book and this really helped

  • @jackwright517
    @jackwright517 ปีที่แล้ว

    WHOA! This is super clear and well explained. 🤯

  • @tetuaoro
    @tetuaoro 3 ปีที่แล้ว +1

    Ownership animation amazing thx fully

  • @Tr3Gee
    @Tr3Gee 5 ปีที่แล้ว +3

    Thanks for such a clear explanation. The animations really helped, lol. Thank you YouCodeThings

  • @ailuros_
    @ailuros_ 5 ปีที่แล้ว +1

    Nice style making video. Very fun!

  • @davidgromer2117
    @davidgromer2117 3 ปีที่แล้ว

    Hi,
    at 4:11 you made an example which does not allow a copy of x to a because of rule 2. So far I understand this. Could you please explain why a copy would be ok if we would assign the following:
    let x = "Hello World";
    let a = x;
    println!("{},{}", a, b);
    So there must be a difference between let x = "Hello World" and let x = String::from("Hello World").
    I heared something about string literal and string type but I do no really get the difference.
    Is "Hello World" stored at the stack?
    Thanks

  • @DwarkeshPatel
    @DwarkeshPatel 4 ปีที่แล้ว

    This is such great content. Thank you!

  • @adinesh7989
    @adinesh7989 6 ปีที่แล้ว +19

    Great video. Too much work into each video. I like it.

    • @YouCodeThings
      @YouCodeThings  6 ปีที่แล้ว +5

      Thank you! I got way too into those animations in this video!

  • @joelmontesdeoca6572
    @joelmontesdeoca6572 2 ปีที่แล้ว

    This explanation was amazing!

  • @shibasispatel6624
    @shibasispatel6624 5 ปีที่แล้ว

    You are a great teacher. Glad I found your channel..

  • @xbony2
    @xbony2 4 ปีที่แล้ว

    This is hella professional, great work.

  • @oroneki
    @oroneki 6 ปีที่แล้ว +1

    Oh! (...) my! (...) God! That is gooold! Thanks so much! Cheers from Brazil!

  • @borys4206
    @borys4206 2 ปีที่แล้ว

    I like your videos and its style! Thanks!

  • @vedantnn7
    @vedantnn7 3 ปีที่แล้ว

    you really teach in very nice manner, instant subscribe

  • @laviray5447
    @laviray5447 2 ปีที่แล้ว

    4:42 when the variable X becomes invalid, what exactly then it equals to? what will be the value of X when it comes invalid?

    • @wutong4524
      @wutong4524 2 ปีที่แล้ว +1

      When it becomes invalid, its value is still "hello", but isn't anymore after it became invalid. If you try to access it, it will throw an error (The compiler will throw an error because it's intelligent).

  • @king_james_official
    @king_james_official ปีที่แล้ว

    7:18 wouldn't &a[0..2] return hel? same for the second one, it's one letter too long

  • @penta5421
    @penta5421 4 ปีที่แล้ว

    Damn, didn't understand this up until now. After watching the video, it kind of clicked and I actually understood! Thanks :D

  • @janniswildermuth1499
    @janniswildermuth1499 6 หลายเดือนก่อน

    Really great explanation, thank you!

  • @arcticspacefox864
    @arcticspacefox864 5 ปีที่แล้ว

    I love your video😂 it was great and interesting! Please continue your style

  • @ysuv5563
    @ysuv5563 11 หลายเดือนก่อน

    I had to laugh so hard after seeing the angry face at 2:00
    I have very little sleep, but this made me laugh hard. Thank you for making me laugh and thank you for the explanation.

  • @jithind-feverx2818
    @jithind-feverx2818 3 ปีที่แล้ว

    Ownership explained clearly ❤️❤️

  • @codewithnws3544
    @codewithnws3544 ปีที่แล้ว

    Hey can you share the idea of creating this video like in the 2d drawing with the animation, what softwaresthat you had used?

  • @marusdod3685
    @marusdod3685 4 ปีที่แล้ว

    ive never programmed in rust before, but why shouldnt we be able to have two pointers pointing to the same address? Like if I just wanted to iterate over an array or linkedlist I would probably need many variables pointing to the same location

  • @guillaumebogard5880
    @guillaumebogard5880 5 ปีที่แล้ว

    Your channel is amazing ! Keep up the good work :)

  • @quangle5701
    @quangle5701 3 ปีที่แล้ว

    Excellent explanation ! Thank you very much.

  • @fabiomarsiaj8172
    @fabiomarsiaj8172 4 ปีที่แล้ว

    Dude your videos are super good, keep going and thank you :)

  • @ktlknss
    @ktlknss ปีที่แล้ว

    thanks so much, I was wondering why the & was used sometimes but now I get it!

  • @docentealejandrocarrillo471
    @docentealejandrocarrillo471 4 ปีที่แล้ว

    This video is more explained than the Rust Book.

  • @WizardOfArc
    @WizardOfArc 5 ปีที่แล้ว +1

    These are entertaining and informative - thank you

  • @LakshmipathiG
    @LakshmipathiG 4 ปีที่แล้ว

    Great thanks! Excellent stuff.

  • @GlebEagle
    @GlebEagle 2 ปีที่แล้ว

    Wow, this explanation is awesome!)🦀❤

  • @kenny-kvibe
    @kenny-kvibe 3 ปีที่แล้ว

    Good descriptive video, simple and concise, thank you!

  • @blue_lobster_
    @blue_lobster_ 5 ปีที่แล้ว +1

    Super cool video! Subscribed!

  • @mateuszgrzonka3826
    @mateuszgrzonka3826 4 ปีที่แล้ว

    Love your vids!

  • @tengkuizdihar
    @tengkuizdihar 6 ปีที่แล้ว

    Wow this is well explained and really consice and clear. Very good job.

  • @doyourealise
    @doyourealise 5 ปีที่แล้ว

    the best video on ownership amaizng

  • @anchalgupta4860
    @anchalgupta4860 2 วันที่ผ่านมา

    Best video ever

  • @aiomixrecords
    @aiomixrecords 6 ปีที่แล้ว +1

    You are great, what do you think is the best way to represent a Cyclic Graph with multiedges in-memory store and enable parallel reads/writes concurrently to the graph? .. am coming from erlang/elixir world where the shared memory is a sin, but I could use ets(memory erlang term storage) and let the genservers/processors(independent heap) get copies from the ets , now my question, how borrowing feature is diffrenent? Is the data is copy as well like elixir? Do you recommend me to move to rust instead of elixir ? Is it possible to have more parallelism in rust more than elixir? I think parallelism algorithm highly depend on shared memory approach? Elixir and rust seem they share a lot, thank you for this amazing work

    • @YouCodeThings
      @YouCodeThings  6 ปีที่แล้ว +2

      I love Elixir as well! They solve different problems. If you need something really fast where you can have a very good understanding of the nuts and bolts, I'd choose Rust.
      Elixir has a larger ecosystem (due to the Erlang ecosystem interop as well) and feels quicker to build distributed systems in.
      The real question is, why not both?
      There's a library called `Rustler` that lets you call Rust from elixir. This might be useful if you have a small piece you need to make performant.
      Finally check out this conference talk. It's an actor library written in Rust, and demonstrates some incredible features.
      "Type Safe & High Perf distributed actor systems with Rust" - th-cam.com/video/qr9GTTST_Dk/w-d-xo.html
      Thanks for the comment! =D

    • @aiomixrecords
      @aiomixrecords 6 ปีที่แล้ว +2

      Thank you a lot for your quick response, i actually was thinking of enabling both to work together where rust work as engine for the graph and receive requests from genservers(elixir)(handling concurrent connections) this way I will take the best from the two languages. thanks again for this amazing content, pls keep up the good work. All the best, am going to watch the link ;)

  • @TheOMGPoPCorn
    @TheOMGPoPCorn 5 ปีที่แล้ว

    Just what I needed. Great job!

  • @JoshuaKisb
    @JoshuaKisb 6 ปีที่แล้ว

    hey this looks like the programming language i was thinking of one day making. except i dont understand why they changed the syntax, whats with all that ! ! stuff and why does it become read only when borrowed. i dont get that

  • @ruis2345
    @ruis2345 4 ปีที่แล้ว

    Well explained, hats off

  • @1337CodeMaster
    @1337CodeMaster 3 ปีที่แล้ว

    Very well explained! Thank you so much :D

  • @KarimAlbakry
    @KarimAlbakry 6 ปีที่แล้ว +6

    you forgot to mention that this only for reference types not value types

  • @AbhishekNigam
    @AbhishekNigam 5 ปีที่แล้ว

    Explained really well!

  • @EngineerNick
    @EngineerNick 4 ปีที่แล้ว

    Thankyou for this clear explanation :)

  • @elimgarak3597
    @elimgarak3597 4 ปีที่แล้ว

    Great video! Thank you so much!

  • @Pluvo2for1
    @Pluvo2for1 ปีที่แล้ว

    Is the idea of the heap the same as c++? That is, the heap is extra memory the program requests from the OS while the program is running?

  • @harrimahlstrom7706
    @harrimahlstrom7706 4 ปีที่แล้ว

    Realy good explanation!!!

  • @cyko5950
    @cyko5950 5 หลายเดือนก่อน

    this is brilliant

  • @gbrls_yt
    @gbrls_yt 5 ปีที่แล้ว

    Hey man! good job, keep it up

  • @renatajakubowicz9664
    @renatajakubowicz9664 6 ปีที่แล้ว

    Thanks for teaching Rust!

  • @hagenlens1403
    @hagenlens1403 4 ปีที่แล้ว +1

    This video is so fucking great.

  • @phildevtv409
    @phildevtv409 2 ปีที่แล้ว

    Thx for great explanation!

  • @YummyRed
    @YummyRed 4 ปีที่แล้ว

    Maaan, you should make more learning videos. It's damn funny and useful.

  • @niravprajapati1267
    @niravprajapati1267 2 ปีที่แล้ว +1

    Good work :)

  • @wishnuprathikantam
    @wishnuprathikantam 4 ปีที่แล้ว

    Hey @youcodethings Great content 👍, please do more videos , if possible regularly!

  • @YouCodeThings
    @YouCodeThings  6 ปีที่แล้ว +34

    Tell me, what can I do to become the best coding channel for you?

    • @wildtiger670
      @wildtiger670 6 ปีที่แล้ว +26

      Give us more! :D

    • @natecoley160
      @natecoley160 6 ปีที่แล้ว +3

      give us examples of that is rust was created for - safe async/parallel programming.

    • @ubermons
      @ubermons 6 ปีที่แล้ว +3

      Make a playlist of this!

    • @aeroball8360
      @aeroball8360 6 ปีที่แล้ว +2

      my only suggestion is slower pace. Watching your videos on normal speed is like watching other coding videos at x2 speed. If someone wants it faster they can always up the speed at normal quality, but trying to down the speed to 0.75 is weird and sounds choppy thanks to however youtube is encoding the speed change.

    • @ailuros_
      @ailuros_ 5 ปีที่แล้ว

      You have done an amazing job so far. I wish your videos had subtitles but I know it's so hard. Maybe speaking a little bit slower it's a tip too, since I am not a native english speaker. That said, this channel is great! Keep it up!

  • @andersmusikka
    @andersmusikka 4 ปีที่แล้ว

    What microphone do you use? You have spectacularly good audio quality.

  • @kcru240
    @kcru240 4 ปีที่แล้ว

    I feel you sound like Dr. Seuss: there is a nice rhythm to the way you talk.

  • @Nate-gi7no
    @Nate-gi7no 4 ปีที่แล้ว

    SICK VIDEO!

  • @orochi639
    @orochi639 ปีที่แล้ว

    Good explanation

  • @darkcheese1
    @darkcheese1 4 ปีที่แล้ว

    nice explanation, thank you :)

  • @dusvn1484
    @dusvn1484 28 วันที่ผ่านมา

    Nice video!

  • @bharathhariharan4750
    @bharathhariharan4750 4 ปีที่แล้ว +1

    Why aren't you making new videos...your videos are great.

    • @YouCodeThings
      @YouCodeThings  4 ปีที่แล้ว

      Appreciate it! A lot going on. Currently working on some larger game projects. Want to eventually make some videos on that process.

  • @henrytan5707
    @henrytan5707 4 ปีที่แล้ว

    Love it.

  • @geeksesi
    @geeksesi 5 ปีที่แล้ว

    amazing. thank you.

  • @thengakola6217
    @thengakola6217 3 ปีที่แล้ว

    No, ur an amazing person *inserts keanu.jpg*

  • @IshanDassanayake07
    @IshanDassanayake07 3 วันที่ผ่านมา

    &mut str is not possible as &str is immutable

  • @michelkazi3112
    @michelkazi3112 4 ปีที่แล้ว

    Holy shit. I understood this.

  • @asksejsbo331
    @asksejsbo331 2 ปีที่แล้ว

    hmm, but why does this code work then:
    let i = "ds";
    let mut ii = i;
    ii = "yoyoyoy";
    println!("{}", i)
    this prints "da", which indicates that the value was copied. But judging from your explanation this shouldnt even compile

    • @YouCodeThings
      @YouCodeThings  2 ปีที่แล้ว +1

      str literals are immutable and copy. `ii` ends up a copy of `i`, and there is no ownership to memory on the heap.
      However String points to memory on the heap and doesn't implement Copy, which then causes the compilation issue.
      Example: play.rust-lang.org/?gist=9ae38ace6a310ca4c2d55077d77635e4

  • @kangalio
    @kangalio 6 ปีที่แล้ว +1

    Thank you! ^.^

    • @YouCodeThings
      @YouCodeThings  6 ปีที่แล้ว

      Thank you for the suggestion!!! :)

  • @ladyViviaen
    @ladyViviaen 3 ปีที่แล้ว

    i FINALLY learned pointers

  • @cd-stephen
    @cd-stephen ปีที่แล้ว

    good vid ty - new sub

  • @SKyrim190
    @SKyrim190 3 ปีที่แล้ว

    Why do I still find this confusing? D: