Rust’s Most Unique Feature

2024 ж. 22 Мам.
15 424 Рет қаралды

In this video, I’ll take a closer look at how Rust manages memory with an ownership model, which is quite unique and really powerful. Stay tuned to find out what it is exactly, how it works, and why you need it.
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis
🔥 GitHub Repository: git.arjan.codes/2024/rustown
💻 ArjanCodes Blog: www.arjancodes.com/blog
✍🏻 Take a quiz on this topic: www.learntail.com/quiz/twmfal
Try Learntail for FREE ➡️ www.learntail.com/
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
The 30-Day Design Challenge: www.arjancodes.com/30ddc
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
Social channels:
💬 Discord: discord.arjan.codes
🐦Twitter: / arjancodes
🌍LinkedIn: / arjancodes
🕵Facebook: / arjancodes
📱Instagram: / arjancodes
♪ Tiktok: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean
🎥 Video edited by Mark Bacskai: / bacskaimark
🔖 Chapters:
0:00 Intro
1:07 Basic rules of ownership in Rust
1:58 Borrowing
6:14 Stack Vs Heap
9:44 Lifetimes
11:23 Conclusion
12:43 Outro
#arjancodes #softwaredesign #python
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

Пікірлер
  • 👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis

    @ArjanCodes@ArjanCodesАй бұрын
  • would love to see more rust content similar to your python content - design patterns, etc.

    @srivatsa1193@srivatsa1193Ай бұрын
    • Design patterns are the same no matter the language lol

      @Fran-kc2gu@Fran-kc2guАй бұрын
    • Actually, they can be quite different if you do not use OOP. Compositional programming or data driven programming requires different patterns that are more suitable if you can't use for example inheritance. And usually they are a bit more counter intuitive. So for me as well: I would love to see some Rust design pattern content ! 🎉

      @TheiPodMac1234@TheiPodMac1234Ай бұрын
  • 6:36 What you say here is not quite right: s2 is not allocated on the stack. On the stack, there is only a "fat pointer" which points into the contents of s1 on the heap. I.e. it references data within s1. This is also made clear by the "&" in its type.

    @Far_Gem@Far_GemАй бұрын
  • Thank you for this intro to Rust ownership model. Would love to see more Rust content in your Channel.

    @iduran@iduranАй бұрын
  • Super excited that you've started creating Rust content!

    @tyler209459023523@tyler209459023523Ай бұрын
  • Now that you mention it... I've actually started following the channel for the Architecture content like 2 and a half years ago. But I am a Python developer and I enjoy the “Python view” on architecture designs in contrast of the Java view of many bibliography. I am also liking Rust, so having **also** content in Rust is also a plus 😄

    @_baco@_bacoАй бұрын
    • That's really cool to hear! I'm glad you're enjoying the content, thank you for the support!

      @ArjanCodes@ArjanCodesАй бұрын
  • Thanks for a great explanation of ownership in Rust, which I've just begun to learn. In other languages I kind of assume anything declared inside a function is stored on the stack, and global variables on the heap. Having control over memory in this way is something new to me. Great stuff Arjan - more on Rust would be great!

    @wizardfix@wizardfixАй бұрын
  • love to see more rust

    @RobertoDuransh@RobertoDuranshАй бұрын
  • Rust has been my favorite language for a while now, and the reason is actually one of your latest points. I realized that the borrow checker was making me structure my code better. I've actually picked up Python after this happened, and learned that I liked it more than I realized. Not really the language to be honest, more so the tooling and ecosystem. I'm planning on trying out pyo3 in the future on my projects, so hopefully that will go well.

    @damymetzke514@damymetzke514Ай бұрын
  • Thank you for doing this great video. You explained a great deal of the main concepts in the first chapters of the Rust book in very simple examples. I'll be keeping this as a reference.

    @shibak4@shibak4Ай бұрын
  • love the rust content!!

    @ajmash9745@ajmash9745Ай бұрын
    • Glad to hear that! :)

      @ArjanCodes@ArjanCodesАй бұрын
    • From comments it is pretty obvious that the community craves for a mix of Rust and Python content. Another idea is to walk through common Rust/Py projects: Modin, PyO3, Polars, Pydantic 2 etc

      @takis88@takis88Ай бұрын
  • Thank you, for explaining ownership and borrowing content in such an easy way, But if possible, then please make more descriptive video for particularly Rust content.

    @SuperHardik12345@SuperHardik12345Ай бұрын
  • I honestly would love if you did segments and concepts for most of the more used languages. This channel always felt like one tailored to the more intermediate devs. And i think getting an insight in how other languages solves certain problems helps greatly in appreciate how things are built and why certain patterns work better in one language over another.

    @GOTHICforLIFE1@GOTHICforLIFE1Ай бұрын
  • Hi @ArjanCodes, as always, a great video! I have learned a lot from you over all the videos over the years, both for conceptual design, and for specific languages. One thing that might be considered (maybe just for me) and what was a little distracting: all the "hover-over" pop ups that come (which are of course totally useful for the programmer) make it (for me at least) difficult to follow along. Maybe you can selectively disable these for your presentations. I look forward to learning more about program design -- and Rust, my new favourite thing ;-) -- from you in the future! Cheers from Bremen! Paul

    @pjgierz@pjgierzАй бұрын
  • Seeking for more rust videos from you

    @naveenr4030@naveenr403025 күн бұрын
  • Mojo uses the same ownership model except that values are borrowed by default. Value copy must be explicit and, coming from python, I prefer that approach. Thank you, Rust

    @sebastiencourtois8696@sebastiencourtois8696Ай бұрын
  • I can't wait for next April 1st to see if Arjan do a Visual Basic video 😇

    @PhunkyBob@PhunkyBobАй бұрын
  • Nice. Essential/fundamental Rust concepts like this are a great addition to your channel and works well alongside your Python content. 👌👍

    @djl3009@djl3009Ай бұрын
  • yes, more Rust please. Thank you Arjan!

    @masiarek@masiarekАй бұрын
  • I am working a lot with Python and the sklearn-Library. For analysing labels of 1 plant my resources are enough (16GB, M1 Apple). Connecting data from all plants is a story for the future. Now I am learning and refreshing my knowledge about Linear Algebra. Reducing dependencies works perfect with Random Forest Regressors and is running very fast. Work with flax, Tensorflow or rewrite Important critical functions in Zig or Rust? Apple also delievered mlx at 2024-02. A lot of questions… I love and enjoy Your Rust-Stuff also as Python-Videos!👍

    @alexanderzikal7244@alexanderzikal7244Ай бұрын
  • Rust is incredible. I started learning it as a way to speed up my Python and fell in love. I try to use it when I can.

    @AceofSpades5757@AceofSpades575728 күн бұрын
    • I'm glad you're having a positive experience with Rust! Thank you for the comment

      @ArjanCodes@ArjanCodes28 күн бұрын
  • I love the Rust content on the channel! Hope to see more!

    @phortheman@phorthemanАй бұрын
    • Glad you enjoy it!

      @ArjanCodes@ArjanCodesАй бұрын
  • I remember once hearing someone say "Python doesn't have variables," and I had no idea what they meant. But in contrast, you can really tell the difference between this model, where a name owns a value directly, and Python's, where names and values float in completely separate worlds.

    @jamesarthurkimbell@jamesarthurkimbellАй бұрын
  • "This leads to better design" This is EXACTLY why I think that Rust has a great future in store. Rust is the first significant innovation in programming languages in three decades, after the invention of the object-oriented paradigm. OK, support for co-operative multi-tasking through `async` functions was also a significant innovation. But Rust has revolutionized type systems and memory models, which I think is a bigger innovation, and definitely of greater importance for the future of programming.

    @TheEvertw@TheEvertwАй бұрын
  • Thank you. Sure, I would like to see more of your content about Rust, even pyo3 for Python-Rust

    Ай бұрын
  • The perfect length

    @aaaaaaaaaaaaaaaaaaaaaaaaaaeeee@aaaaaaaaaaaaaaaaaaaaaaaaaaeeeeАй бұрын
  • 7:25 Borrowing and references work just the same for stack-allocated data. For example, &i32 is a valid type, although i32 is a primitive and fully stack-allocated (implementing the Copy trait).

    @Far_Gem@Far_GemАй бұрын
  • At 9:21 why can you move the string inside the fuction from the heap to the stack without making any changes to the reference? Isnt the String variable still on the heap? Confused 🤪

    @kkollsga@kkollsgaАй бұрын
    • Arjan's explanation is unfortunately wrong here. &str is not a stack-allocated type, it's a reference to a slice of a string which lives on the heap. The Rust compiler is clever enough to be able to accept a reference to an "entire" string ("&String") in place of a reference to a slice ("&str"). If you want to know more details, you can google "Deref Coercion".

      @Far_Gem@Far_GemАй бұрын
  • Loved your Python content but definitely excited to see more Rust content and design patterns!

    @AbdolaMike@AbdolaMikeАй бұрын
    • Awesome, thank you!

      @ArjanCodes@ArjanCodesАй бұрын
  • Visual Basic for the win! I'm willing to bet, a good chunk of our economy relies on excel "databases" with some half-baked VBA scripts.

    @UNgineering@UNgineeringАй бұрын
  • So does that mean when I assign a variable to another variable in python, it really just creates a pointer to that original variable under the hood if I don’t use something like copy.deepcopy()?

    @personabrahamaudu@personabrahamauduАй бұрын
  • How did you make the terminal as a page?

    @deadlooop@deadlooopАй бұрын
  • Thank you....

    @hubstrangers3450@hubstrangers3450Ай бұрын
    • You're welcome!

      @ArjanCodes@ArjanCodesАй бұрын
  • Python and Rust, powerful buddies.

    @dirkschannel5817@dirkschannel5817Ай бұрын
  • please reply : data science and machine learning with rust , is it possible ?

    @aligharaibeh3761@aligharaibeh3761Ай бұрын
  • Please please please... more rust !!!

    @AbhishekYT-ht9ul@AbhishekYT-ht9ulАй бұрын
  • This video is exactly 13:37 (leet). That was clearly on purpose

    @miguelangelsalazardetroya9476@miguelangelsalazardetroya9476Ай бұрын
    • It's the optimal video length 😎

      @ArjanCodes@ArjanCodesАй бұрын
  • Heap, stack, would love a deep video about how memory works, seems like a fundamental. Great video as usual

    @tobidegnon4409@tobidegnon4409Ай бұрын
  • More rust content!

    @Bryen89@Bryen89Ай бұрын
  • I also do not think of your channel as a Python channel, came up as a python dev but write JavaScript now and its equally valid!

    @internetrush@internetrushАй бұрын
  • What do you think about Zig?

    @sinancetinkaya@sinancetinkayaАй бұрын
  • More RUST content please, Arjan :)

    @79SagiTaurus@79SagiTaurusАй бұрын
  • Great video as always. I only comment this because there are lots of pro-rust comments below, but I would prefer Mojo content instead. 🔥 There are enough Rust channels on KZhead, but high quality Python and esp. Cython, Zig or Mojo is scarce.

    @DataPastor@DataPastorАй бұрын
  • Which GUI do You prefer in Rust?

    @alexanderzikal7244@alexanderzikal7244Ай бұрын
  • look man we are here to learn pattern and concepts and Rust has one of the best paradigm go at it we LOVE python we need it, and we Love most of all learning about paradigms and other languages, what would be amazing is if you try to dig in Go, Rust,Python and do some kind of comparing their concepts, I love python and Go they have alot of similarities even the author of Go confessed that they got inspored alot of python and that python is the closest language to Go

    @maroben225@maroben225Ай бұрын
  • I was thinking about Rust Foundation and was like wtf...

    @cherry-55@cherry-55Ай бұрын
  • Great video. However, please clear your console before you compile each time

    @adriancruz2822@adriancruz2822Ай бұрын
  • Rust in practice manages memory with Arc

    @bocckoka@bocckokaАй бұрын
  • Ill take rust content with a python bias over typescript any day of the week.

    @JT-mr3db@JT-mr3dbАй бұрын
  • I got 60% of this video😂, but anyway, I'm nothing understanding about lifetime now🤦‍♂

    @alifakhar3687@alifakhar3687Ай бұрын
  • I love your videos, but may I suggest not doing so many cuts to show yourself in fullscreen? It’s very distracting, and surely it adds more work for you to edit. ;)

    @greob@greobАй бұрын
  • TURN IT INTO A RUST BASED CHANNEL PLEASE

    @Aceptron@AceptronАй бұрын
  • Yes, great, but why? This whole thing about rust just because C has "memory problems" so complicated is C or c++ that they had to invent a new language to avoid having to learn xd, I still don't see the great advantages of switching to Rust. What about Mojo 🔥btw.

    @alejandroioio6784@alejandroioio6784Ай бұрын
    • Mojo does not seem very useful to be honest. Dictionaries in mojo are slower than in python.

      @Michallote@MichalloteАй бұрын
    • Good question. Because we want a language that can provide the performance of C and C++. A language one can use anywhere one might use C and C++, for example writing operating systems., writing games, embedded systems, operating systems, compilers/interpreters for other languages, web services that need efficiency. In fact pretty much anything. Because we want a language that while as performant as C and C++ helps prevent all the problems that can happen with those languages, problems that cause random failures, crashes and security issues. Which Rust does if we look at the statistics and success stories published by the likes of Microsoft, Google and others. Because we want a languages that helps us to build well designed and maintainable code. "What about Mojo?". Well Rust was conceived a long time ago, I suspect before Mojo. If Mojo can do all the above then why not. I have no idea really but from what little I have seen of it I suspect it cannot.

      @Heater-v1.0.0@Heater-v1.0.0Ай бұрын
    • ​@Michallote you can always implement your custom dictionary

      @alejandroioio6784@alejandroioio6784Ай бұрын
    • ​@Heater-v1.0.0 yes but this doesn't answer my question c++ can do all of that in fact if you want success examples omg c++ has plenty of that with c++ you have a enormous code base an enormous community and 40 years of experience the world is basically writing in c or c++ at this point of the game doesn't make sense change to another language that "does the same" something that we can't be 100% because RUST is very new and all that for what just because is more "safety" come on that is madness and what means security any ways most of the attacks came from people to people c++ is the best choice for sure.

      @alejandroioio6784@alejandroioio6784Ай бұрын
    • @@alejandroioio6784 All that you say is true. C and C++ have been used to create countless wonderful things over many years. Of course there is a huge community of users. I love C, been using it since 1984, because it's a small, simple, fast language that one man can write a compiler for in a reasonable amount of time. C++ not so much, been using it since 1998. It is huge and complex and ugly and seems to be getting worse with every new standards release. What I disagree with is the "just because of more safety come on that is madness". As you know C and C++ allow the programmer to make all kinds of silly mistakes in thousands of ways. That is why those languages have "coding guidelines" and "coding standards". huge documents with hundreds of pages and thousands of rules and do's and don'ts that one has to code against and review code against. That is a lot of tedious mental effort. Most of it is because of the lax way the languages allow programmers to make silly memory use mistakes. Not many can afford the time or have the stamina to do all that so we end up with code that is buggy and requires a great deal of testing and debugging, even after it has gone into production. And code that is prone to security issues. Enter Rust. Rust is far more rigorous about type and memory use errors. It checks so many things. It removes the need for most of those coding standards, it removes the need for all that review and debugging. Basically it automates away a lot of tedious drudgery. Programmers love to be lazy and automate as much as possible, how could they not love what Rust offers them? No sensible Rust head is suggesting rewriting everything in Rust, that is obviously a silly idea, lost of work for not much gain that will likely create more problems than it fixes. But for new projects or extending old projects Rust is very desirable for the reasons given. C and C++ are not going away any time soon but it's not a zero-sum game, Rust can thrive and work with other languages.

      @Heater-v1.0.0@Heater-v1.0.0Ай бұрын
KZhead