The Rust Standard Library is SO Confusing...Until Now!

Поділитися
Вставка
  • Опубліковано 22 тра 2024
  • To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TravisMedia . The first 200 of you will get 20% off Brilliant’s annual premium subscription.
    If you're new to Rust you might find the Rust Standard Library REALLY confusing! It's just too much information there and most of it looks like a foreign language!
    But learning and using the standard library is KEY to success with Rust. Wouldn't you want to use this performance and memory-optimized, battle-tested code put together by Rust experts or just try to do everything from scratch?
    It truly is like a Swiss army knife for the Rust language.
    If you are struggling to make sense of it or to grasp how to use it effectively then be sure to watch this video.
    *This video was sponsored by Brilliant
    Timestamps
    00:00 Intro
    01:13 1 Why you can't make sense of it
    04:23 Sponsor
    05:37 2 An outline of the library
    09:35 3 A tool for access
    Join the Imposter Devs community - imposterdevs.com
    Updated Udemy deals - travis.media/udemy
    ** Career Path Coding Tracks **
    Web Developer - geni.us/jBigBd
    Software Engineer - geni.us/AbMxjrX
    Machine Learning - geni.us/GporLlT
    Python Developer - geni.us/tv2FJBU
    DevOps Engineer - geni.us/MgHtJ
    ** My Coding Blueprints **
    Learn to Code Web Developer Blueprint - geni.us/HoswN2
    AWS/Python Blueprint - geni.us/yGlFaRe - FREE
    Both FREE in the Travis Media Community - imposterdevs.com
    My microphone - amzn.to/3sAwyrH
    ** I write regularly **
    travis.media
    ** FREE EBOOKS **
    📘 travis.media/ebooks
    LET'S CONNECT!
    📰 LinkedIn ➔ / travisdotmedia
    🐦 Twitter ➔ / travisdotmedia
    🙋🏼‍♂️ Website ➔ travis.media
    #rustprogramming #rustlang #rust
    ** Some of the links in this description may be affiliate links that I may get a little cut of. Thank you.
  • Наука та технологія

КОМЕНТАРІ • 75

  • @TravisMedia
    @TravisMedia  2 місяці тому

    To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TravisMedia . The first 200 of you will get 20% off Brilliant’s annual premium subscription.

    • @hammerheadcorvette4
      @hammerheadcorvette4 2 місяці тому +1

      🤔🤔 4:05 Where's the link to the Rust book? You said you'd put a link, but I see everything but it? 🤔🤔

    • @xE92vD
      @xE92vD 2 місяці тому

      ​@@hammerheadcorvette4just search for rust the book

  • @rtdietrich
    @rtdietrich 2 місяці тому +25

    I do it exactly as you described. At the beginning I wanted to avoid it because it means a lot of work, but what has to be done has to be done

  • @jongeduard
    @jongeduard 2 місяці тому +6

    For me learning the language was all those things at the same time. Analyzer, Book, Docs, Rustlings, while reading trying everything extensively. Hours of clicking around through Rust source code. Everything is zo amazingly accessible.
    And I really have to say that the library source code is actually very easy to read, which you showed for a short time in the video. It has been written in a beautiful way.
    If anyone has ever looked at C++ source code, oh man, what a difference. Like from another planet.
    Most important for me was the choice of learning this language and making it a goal on a different level. Professionally I develop in C# mostly, but I have always explored lots of languages. And I became aware Rust as really a different kind of thing which is clearly going to be ever more important in the future, so I decided to go 100 percent for it. And I feel thankful for this. It's now my favorite programming language.
    And yeah, some mention Zig as great as well, but that language is less mature and further away from mainstream. And Rust is still better in safety. I might explore some day as well though. Maybe it's amazing too.

  • @pedroluzio
    @pedroluzio 14 днів тому

    Just a tip, in VScode type hints are not just ON/OFF, you can configure them so that they can show only when you press, CTRL/CMD+OPTION/ALT, with "editor.inlayHints.enabled": "offUnlessPressed", and you also have the reverse. I like this feature, because the hints can become verbose and push ur code 1000 characters to the side. I usually have them off till I press.

  • @patto2k358
    @patto2k358 2 місяці тому +4

    10:16 that's the standard library implementation itself

  • @alfred0231
    @alfred0231 2 місяці тому +3

    I think that the trig functions give a quick insight into how Rust standard library structures code.

  • @crab-cake
    @crab-cake 2 місяці тому

    when i first started learning rust 3-4 years ago i had that exact problem. the docs didn't make sense to me for the longest time. i think i would've progressed much faster if they weren't so technical and didn't lack context. the book is great and rustlings is also great, but i think it would be helpful if there was an interactive repl tutorial built into the browser. not sure if you've heard of sveltekit before, but it has a wonderful repl tutorial.

  • @kennystrawnmusic
    @kennystrawnmusic 2 місяці тому

    Starting with the core and alloc libraries - which are what you need to use when following Rust OSDev tutorials - is what made the standard library easier to grasp on my end. Once you know how to navigate the core library and once you know how to navigate the alloc library, then by the time you try to navigate the standard library, you’ve already learned bits and pieces of it.

  • @jasonbraithwaite9204
    @jasonbraithwaite9204 5 годин тому

    Excellent video, really invaluable, thank you 👍

  • @akauppi2
    @akauppi2 2 місяці тому +2

    Today, I came across an SO comment about std::sync::mpsc (the channel-thing). “Some think it wasn’t a good idea to place channel to the std, but now it’s too late.” That was insightful. Opened me more braveness to look at non-std crates, instead.

  • @dabunnisher29
    @dabunnisher29 2 місяці тому

    This is SOOOOO TRUE!!!! Thank you for all you do.

  • @yiraqcic1348
    @yiraqcic1348 2 місяці тому +7

    More and more Rust content. Thanks a bunch for everything you do !

    • @CallousCoder
      @CallousCoder 2 місяці тому

      I have some rust stuff too, but even more Zig stuff. Which is just a better low level language ;)

  • @subhankarn
    @subhankarn 2 місяці тому

    where is the link for the Rust book?

    • @sammy709
      @sammy709 2 місяці тому +4

      google

    • @TravisMedia
      @TravisMedia  2 місяці тому +4

      doc.rust-lang.org/book/

    • @galk32
      @galk32 2 місяці тому +1

      in terminal: rustup doc --book

    • @subhankarn
      @subhankarn 2 місяці тому

      @@TravisMedia thank you for sharing the link

  • @user-pw6so9mk4p
    @user-pw6so9mk4p 2 місяці тому +3

    Thank you for showing how to read I have been unable to start reading docs after reading the book

  • @simonkalu
    @simonkalu 2 місяці тому +4

    Rust is a power house. It is a well crafted language and to some extent resembles Typescript. I am currently comparing two the two to see where the syntax looks alike etc. It is a very interesting and robust language that cuts across many domains. I tried Rust + Vite + Wasm and the result was amazing. @Travis, what is your view on Rust job market or getting a Rust jobs?

    • @TravisMedia
      @TravisMedia  2 місяці тому +4

      I feel like the Rust job market currently is largely if not mostly a senior Rust engineer market. Things could definitely change though with more adoption and use cases. It’s a tough language to get good at, but once good at it I think one could become very marketable in it.

    • @simonkalu
      @simonkalu 2 місяці тому

      @@TravisMedia thanks for the swift response 😊. What's your thoughts, Rust looks like something that will take forever to master because of the volume of materials that one has to consume to understand how things work to solve problems? 😀. I am a programmer based in Nigeria 🇳🇬 and work in the oil and gas sector. I am currently, looking for a remote gig to support my income. What tech stack can one easily focus on to quickly grab a remote job especially for those of us that live in Africa. What lang is in high demand from your view? Kindly reply

    • @Hellbending
      @Hellbending 2 місяці тому

      @@simonkalu not exactly qualified to answer, but I’ll give my two cents lol
      If you would google any of the top most used languages, you’re probably going to see something along the lines of JavaScript/typescript as react and python, given the current booming AI industry model.
      Both are pretty much a standard, run-of-the-mill programming languages at this point in time and potentially tough to get a job in due to the fact that yes people love them. Yes, they always need people to work, but it also follows the path of everyone else, which tends to means that you have more competition as well.
      I’m not sure what you’d be able to put to use overall. If you’re wanting to stick within mining and gas etc. type of industry then I could imagine that a low level language like C or C++ might do you some good if you’re looking at moving into something to do with Arduino, or on board chips for instance. (and if you put your head down, and I mean really learn the ins and outs of C and C++.) You’re likely to come away with a benefit that a lot of people don’t end up seeing as they are less common of a language than the aforementioned ones.
      (just be prepared that you are going to have to learn security related content in order to get a good handle on it that, and if you’re going to be using in a sector such as one with regulations of basically any kind)

  • @justiceessiel6123
    @justiceessiel6123 2 місяці тому

    Dfs algorithm in terms of his advice

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 2 місяці тому +1

    The standard library is a really limited, even no regexp there. Yes, you can easily to find 3rd party implementation of version 0.0.36.... But which one to use? How effective and correct the implementation? Nobody knows, you can get an answer like that: It works for me, and hopefully will work for you... You got it.

    • @noahhounshel104
      @noahhounshel104 2 місяці тому +5

      There is no regex implementation in the standard library for exactly the reasons you are asking about in choosing a regex implementation library. There are many possible ways to implement it with their own pros and cons. Since there is no consensus on the best, there is no standard library implementation.

    • @kamertonaudiophileplayer847
      @kamertonaudiophileplayer847 2 місяці тому

      @@noahhounshel104 You touched a very good point, if you know what you need then take own implementation, otherwise use the standard. But the standard is missed in Rust.

    • @noahhounshel104
      @noahhounshel104 2 місяці тому

      @@kamertonaudiophileplayer847 the point is that there's no standard because the people making the standard library aren't mind readers. If you don't know what you want or need, why would they possibly be able to determine that for you?
      Especially when it comes to regular expressions there are hundreds of variations, and the regex itself is an entirely separate language, with languages like Python and Ruby having different, distinct dialects which are incompatible with each other. What version should they implement? Should they allow backtracking in regexes? That runs the risk of some severe bugs like the cloudflare outage in 2019. There are a million implementation specific questions that make your "small" addition to the standard library immensely more complicated than you think it is.
      This is the very reason the Rust developers have expressed regret in the decision to include hashmaps in the standard library. The "standard library" hashmap is orders of magnitude slower than 3rd party implementations because of the compromises they made on the hashing algorithm safety, because it's "default" and they cannot read your code and know if it's appropriate to use a faster, less secure algorithm.

  • @Wilkbezstada
    @Wilkbezstada 2 місяці тому

    Jensen told to not learn code.

  • @CitizensCommunity
    @CitizensCommunity 2 місяці тому

    Oh, I hate the advice 'follow the links.' It's a terrible way to learn, as it never ends and constantly creates new rabbit holes that lead to frustration. I skipped the Rust book, and once I grasped the basic usage by quizzing gippty, I read Mara Bos's 'Rust Atomics and Locks' to transition from Python to low-level code. Looking things up until you can continue reading gives you the context for how things are used and a reason for learning them. Going back and reading the Rust book afterward filled in any gaps I missed and allowed me to understand some points they were making, which I highly doubt I would have grasped if I read it first.

  • @CallousCoder
    @CallousCoder 2 місяці тому +5

    The Rust stdlib is just too big and I hate the factory builder patterns with a passion. That was already a bad idea in Java, why copy it?
    I will never be a Rust fanboy, as a C/C++ guy. I still have to find a way how to have 3 different thread functions access the same vector without using Arc

    • @jackhales6179
      @jackhales6179 2 місяці тому +3

      Rust is cool, Zig is cool, Python is cool, C++ is cool, its all just tech

    • @CallousCoder
      @CallousCoder 2 місяці тому

      @@jackhales6179 Python isn’t cool 😁Python is a toy. 😄

    • @CallousCoder
      @CallousCoder 2 місяці тому +1

      @@jackhales6179 except Python isn’t cool it’s slow 😂

    • @jackhales6179
      @jackhales6179 2 місяці тому +1

      @@CallousCodercool slow 😎

    • @CallousCoder
      @CallousCoder 2 місяці тому

      @@jackhales6179 Naah any language without { } or begin end or that isn't strongly typed isn't cool. 😶‍🌫

  • @patto2k358
    @patto2k358 2 місяці тому

    The micro edits are jarring

  • @christianm4906
    @christianm4906 2 місяці тому +3

    Why consider learning Rust if its future is so uncertain, especially given that there are other languages on the horizon that offer clean interoperability with existing C/C++ and Python code, such as Mojo, CPP2, Carbon, and even Zig? I am under the impression that Rust's approach is a failure from day one. Its future seems likely to resemble that of the D programming language or Dart, with the notable difference that Dart was saved by Flutter, without which it might have failed. In contrast, approaches like TypeScript and C++ seem much more successful in terms of adoption compared to Dart and the D programming language. The Rust extern function approach to integrating with other languages is as good as having nothing at all. This is not a good time to learn Rust. As soon as the first production-ready version of either Carbon, CPP2, or Mojo gets released, Rust's future will resemble the present of the D programming language.

    • @TravisMedia
      @TravisMedia  2 місяці тому +11

      There's some pretty big adoption of Rust (to explicitly move away from C/C++, by recommendation of the US CISA) by Microsoft, Google, etc. Who knows what the future will bring, but I don't see Rust at all going the way of Dart.

    • @christianm4906
      @christianm4906 2 місяці тому +3

      @TravisMedia Then why Microsoft engineers are working on cpp2 an Google engineers are working on Carbon? It's been at least 12 years since we first heard of Rust, and despite the extensive marketing campaign it has received, it is still considered a niche programming language. Don't get me wrong, I'm not saying Rust is a bad programming language. In fact, it might have few missing features in C/C++ , but its approach forces developers to either write everything from scratch or deal with the pitfalls of the 'extern-function approach' for integration with the outside world. The industry has invariably proven that this approach is a failure from day one. A very good example of this is the Dart programming language. It was originally intended to replace JavaScript, and despite being better than JavaScript in many ways, it miserably failed to do so. Similarly, Rust is unlikely to succeed in replacing C or C++. The reason is that Rust and C++ are fundamentally incompatible. I see more future in replacing C/C++ with other approaches such as CPP2 or Carbon if the first production-ready versions of those languages are released, which seems very likely to happen soon. Once that happens, there will be even less chance for Rust to replace C or C++. Mojo also looks a much more attractive alternative than Rust as it can run as fast as C, it offers memory safe features like Rust while being easier to use an compatible with python. Also, note that C++ and TypeScript are very successful languages in terms of adoption because their approach doesn't require rewriting everything from scratch. You just change the extension from .js to .ts in your JavaScript programs and start seeing results in terms of migration right away. Similarly, with C++ and C; you compile a C program with a C++ compiler and start seeing results. That's why industries are reluctant to migrate to Rust. This approach is in opposition to code reusability, which is too important to give up.

    • @CallousCoder
      @CallousCoder 2 місяці тому +3

      @@TravisMedia I am not a real fan of Rust, I will never be a fanboy I don't like verbosity and the indent and bracket heavy syntax. But I don't see it going anywhere. I do believe that Rust won't win the embedded market and realtime markets. I think Zig will jump into those because there's so much C code that will need to be used for ages (especially in critical systems you don't just make a new implementation as code needs to be audited and certified and costs time and money). Zig sits perfectly in there it can use those libraries without function wrappers it can compile everything and it's actually pretty safe.

    • @steveoc64
      @steveoc64 2 місяці тому +2

      @@TravisMedia the CISA recommendation is to choose memory safe languages wherever possible.. it then lists a number of them. Rust is 1 entry in a long list

    • @christianm4906
      @christianm4906 2 місяці тому +2

      @CallousCoder I totally agree with this comment. Code reusability is key for new programming languages to succeed. The trend is clear for programming languages that have been successfully adopted. TypeScript interoperates with JavaScript, C++ interoperates with C, and Kotlin, which I forgot to mention before, interoperates with Java. In this respect, I see a clear advantage of Zig over Rust. Not to mention Mojo, which has not only beaten Rust in performance but also supports memory-safe features with a cleaner syntax and can interoperate with Python. Cpp2 and Carbon solve the problems with C and C++ while offering a cleaner syntax and interoperation with C/C++ code. To add more salt to the wound, Rust has already become too verbose and complex, so much so that even the Rust developers are feeling frustrated with it. I know a few government agencies might be advocating for memory-safe languages, but it doesn't necessarily have to be Rust. In fact, there are memory safety languages out there with far greater adoption than Rust, such as Java, C#, Python, Swift, and Go. And if performance is also important, Rust has to compete with the already industry-established C and C++, now Cpp2, Carbon, Mojo, Zig, and Go. As I said before, it is not a good time to learn Rust and reinvent the wheel in a language just for the sake of doing so. Rust didn't replace C or C++ and it never will. Just check GitHub, Stack Overflow, and other statistics. The truth is that much more code is being written in C and C++ than in Rust. It's been like that for decades. A new programming language, to succeed, needs to guarantee code reusability; otherwise, it will miserably fail

  • @erikpaulsen3111
    @erikpaulsen3111 2 місяці тому +1

    I am still confused and refuse to do homework. The lack of JSON, XML and SQL in the standard library implies that the borrow checker logic dislikes text management and trees.

    • @matthiskalble3621
      @matthiskalble3621 2 місяці тому +17

      No these are things that do not belong Ino the std library as standards for these things might change (eg you need to update it if a new feature comes in one of these languages). That is why there are some de facto standard crates (serde etc)
      For SQL there are just like 1000 different backends, it is not the stdlibs job to support those

    • @matthiskalble3621
      @matthiskalble3621 2 місяці тому +1

      Also it is supposed to be minimal, not feature complete for everthing

    • @andrewf8366
      @andrewf8366 2 місяці тому +4

      Are there languages with those in the standard library?

    • @kitlith
      @kitlith 2 місяці тому

      ​@@andrewf8366python comes to mind

    • @joshuaPurushothaman_
      @joshuaPurushothaman_ 2 місяці тому

      ​@@andrewf8366Python has json I think. I'd say it's fair to have those... I think serde is regarded as pretty standard for use though. Like how python asyncio needs a pip install (iirc), but is pretty much de facto?

  • @deadmarshal
    @deadmarshal 2 місяці тому +2

    Rust is a joke!

  • @kevinkkirimii
    @kevinkkirimii 2 місяці тому

    Unless I have no other option, I am not touching rust again.... Zig all the way.

  • @jazzycoder
    @jazzycoder 2 місяці тому +1

    What's the point of teaching Rust when there's no market for it? Is this just a vanity project or going to be useful moving forward? I am beginning to think Rust is going to end up like Scala are Elixir ..

    • @jordanjohnson714
      @jordanjohnson714 День тому

      I disagree.
      I’m an electrical engineer who learned Rust in my free time because it sounded interesting. I didn’t care about trying to find a Rust programmer job; I just wanted to learn it for fun, because it had some dramatically new ideas. I went into it knowing C, C++, MATLAB, and LabVIEW. (Not including HDLs in this list.)
      It turned out to be a very nice language. I could go on a rant about all the different features I like about it, but you probably aren’t interested.
      I learned it just for fun, but it actually turned out to be a useful tool.
      I see embedded as a super interesting use case for Rust, and I am seeing some interest in using Rust at various workplaces for these applications. Rust’s extremely powerful type system and errors-as-values means it is far easier to avoid bugs in your software. With Embedded, often you just cannot tolerate failure.
      You can prevent not only the memory bugs Rust is famous for, but if you really take advantage of the type system, you can use it to make invalid states unrepresentable and have the compiler prevent a surprising number of logical bugs. It is magical when you experience it.
      I recently completed a program in C I wish I had done in Rust. I wasted a lot of time on issues Rust would have prevented.
      Even when you need to dip into unsafe, which happens in microcontrollers, Rust still does a lot to keep you from making mistakes from its type system. Plus, if you employ good programming practice and keep your code modular, you really only need to use unsafe rust in the sections of code that interface with hardware. (And in practice, you can just use HAL crates that take care of it for you. Note that HAL is not specific to Rust.)
      That’s why it bugs me when those not very familiar with the language say something like “Ah, but if you need to use unsafe blocks, why not just use C anyways?” Because I’d rather have 2% of my code be potentially unsafe than 100%. Plus the other features of Rust just make it much more pleasant to code in… to the point I would use Rust over C++ even if it didn’t prevent any bugs. (Over C though? Maybe… it depends on the project.)
      Rust is new enough it’s not a good choice if you are only learning one language for the purpose of employment. But if you’re employed and want to up your game, or tinker with something new, or even make yourself more employable by having a wider range of experience in addition to your primary language, there is nothing wrong with learning Rust.
      Plus, Rust is growing fast, to the point I really would not be surprised if you could pick up Rust jobs easily 10 or 20 years from now. Rust and Go seem like the only modern languages with a bright future.
      And just to clarify. Rust is a tool, just like C, C++, C#, Java, Go, etc. Use the right tool for the job. Use what you are most proficient in. If you want something quick and dirty and don’t care about performance lost due to GC, don’t worry about Rust; just put something together in Go or whatever else you work fast in.