Understand Rust's Borrow Checker in 5 Minutes

Sdílet
Vložit
  • čas přidán 22. 10. 2021
  • The borrow checker is probably the hardest thing about Rust to understand, which is why I'm explaining it early on. Maybe I missed a few things, oh well.
    Music Used:
    Late Night Radio Kevin MacLeod (incompetech.com)
    Licensed under Creative Commons: By Attribution 3.0 License
    creativecommons.org/licenses/b...
    Hyperfun Kevin MacLeod (incompetech.com)
    Licensed under Creative Commons: By Attribution 3.0 License
    creativecommons.org/licenses/b...
  • Hry

Komentáře • 29

  • @franklinblanco7499
    @franklinblanco7499 Před 2 lety +10

    Excellent video for a Java guy like me! Liked the intro quite a bit.

  • @Mr.Dirkelz
    @Mr.Dirkelz Před 2 lety +12

    Very good video! Good explanations and the visuals make it easier to interperet

  • @EdWestfieldJr
    @EdWestfieldJr Před 2 měsíci

    Thank you! This is the best borrow-checker/mutability/ownership explanation I've seen so far... Could you do one on lifetimes?

  • @jeyzDfoo
    @jeyzDfoo Před rokem +7

    Anyone notice the purple bug? Not animated in RUST

    • @XtremeGamesW2013
      @XtremeGamesW2013  Před rokem +2

      Lol for some reason one of the purple guys had a fragment that kept flying around, and I couldn't figure out what caused it before I released it

    • @Cypekeh
      @Cypekeh Před 3 měsíci +1

      I thought it's a flea walking on my phone screen 😂

    • @Jhiva99
      @Jhiva99 Před 2 měsíci

      literally watched twice thinking it was a coded message. gonna watch again to learn about the borrow checker

  • @AK-vx4dy
    @AK-vx4dy Před 8 měsíci

    Excellent animations !!!! Really picture is worth of thousand words !!!
    I only didn't understand puprose of this falling red dot

  • @boggledeggnoggler5472
    @boggledeggnoggler5472 Před rokem +2

    I like the vibe

  • @vishnukm441
    @vishnukm441 Před rokem +1

    Thanks for this :)

  • @Firelucid
    @Firelucid Před rokem +1

    pretty goooooood stuff

  • @nathanzebedee5263
    @nathanzebedee5263 Před rokem

    this video is awesome

  • @ethankuhrts2799
    @ethankuhrts2799 Před rokem +8

    It's mut not mut 😡

  • @angelomermigis3640
    @angelomermigis3640 Před rokem

    Awesome vid and lmao memory management in narc voice

  • @alexloktionoff6833
    @alexloktionoff6833 Před 7 měsíci

    Can you help the beginner? Is there a possibility for borrow-checker to help to control partial structure updates? I mean can I pass the whole structure to the functions and in&out but borrow checker could help/nag in case called function changed a field value but the rest of the caller function code assumes the value has not been changed/updated? Can you show an example for the structure with the basic u32/int fields?

  • @Turalcar
    @Turalcar Před 10 měsíci

    Understanding Rust's Borrow Checker in 5 seconds:
    compile-time rwlock.

  • @ArsenBilyalov
    @ArsenBilyalov Před rokem

    Thanks bro, i have an exam tomorrow and rust is one of the potential exam questions. This is exactly what i needed to know, nothing more

    • @Cookiekeks
      @Cookiekeks Před rokem +7

      What school is this? I'm curious where they actually teach rust

  • @spicylemonade2694
    @spicylemonade2694 Před 2 lety +2

    Needed this

  • @caspera3193
    @caspera3193 Před rokem

    Good old MS Paint videos

  • @nerdy_dav
    @nerdy_dav Před 8 měsíci +1

    Please please please, don't use floats for Money.
    Off by 1 errors start causing havoc in systems where reconciliation and governance is paramount.

  • @blitzkiek
    @blitzkiek Před 11 měsíci

    Purple bug 😂

  • @alivenumber5
    @alivenumber5 Před 6 měsíci

    Im sorry but i just dont understand how this isnt just the same thing as reference to a const value? So Rusts big claim to fame is that everything is const by default? What am I missing here?

    • @maxave7448
      @maxave7448 Před 5 měsíci +1

      The way I get it, rusts big claim to fame is in the borrow-checker. Rust is so strict with who is responsible for a piece of memory that it gives you a compile-time error if theres something it doesnt like.
      Why is this so useful?
      Some programs have to be low level and have no room for errors. In C, a lot of memory errors will only be caught at runtime which is not good because developers have to test every case to find errors. Rust tells you this during compile time which eliminates a lot of testing work, guaranteeing memory safety without needing to run 100 tests

    • @jcm2606
      @jcm2606 Před 9 dny

      Rust's big claim to fame is that all references contain a lifetime parameter that lets the compiler figure out how long a reference has lived for, to determine if the reference can outlive the value it's pointing to and throw an compiler error if it can. In some cases the lifetime parameter is inferred by the compiler, meaning that you don't need to explicitly state that it exists in your code, but in other cases the compiler can't trivially infer it and so it requires that you manually state it by adding a lifetime annotation to variables containing references, which the compiler can use to "string together" the full lifetime of a given reference as it moves through your code.
      Basically, imagine if you were writing some C code and you referenced a variable to get a pointer to the value of that variable, then you stored the pointer in another struct so that you can refer back to the variable at a later time. In C you'd have to look over the code to make sure that the struct can't possibly outlive the variable that the pointer is pointing to, else you'd have a user-after-free which could cause a segfault, or worse. In Rust that pointer has a lifetime parameter associated with it that tells the Rust compiler how long the pointer has lived for, and the struct would accept its own lifetime parameter that associates the struct's lifetime with the pointer's. That lets the compiler make sure that the pointer doesn't outlive the value it's pointing to, which means you don't have to look over the code as much as you would in C. That is Rust's big claim to fame.

  • @Christobanistan
    @Christobanistan Před 2 měsíci

    ...half assed coverage of topic, promises to continue it but abandons completely...downvote.