How to get started with the standard library?

I've been hacking rust for some time, and have often found I dig into the std library when I need something, and hope to find it there. Often the solution is to be found in an external crate, but that I often find after looking in the std library first.

I've been thinking two things. First is that I should maybe look to external crates first, and secondly that if I knew the standard library better, I'd know when to look there and when not to.

Which brings me to my question. How do you get to know the standard library? Sit down with the official docs and read from start to finish? Have someone done a Book on it? Is there a well known tutorial that I have missed?

I find the standard library to be pretty reasonably structured, so if I'm looking for a type or function to do $X, I'll try a quick direct search for possible names/terms (I have a Firefox keyword search for this), then I'll quickly check the relevant module of the stdlib ("Hmm... does std have a paged array type? checks std::collections Nope."). Assuming those both fail, I'll search (again, Firefox keyword search). If that doesn't turn up anything promising, it's off to DuckDuckGo.

And when DuckDuckGo fails to work, I sigh in resignation and use Google.

Or, if I want a laugh, I'll ask an AI and watch it hallucinate functionality that doesn't exist.

As for how to learn the layout of the standard library... I just kept writing Rust. I've realised as I've gotten older that trying to memorise stuff like the layout of a library is completely pointless for me. I won't remember that stuff unless there's stronger associations, and I build those by using stuff, not staring at module listings.


For me, some ways to learn stdlib

  • always refer to offical std doc first, because it's one of the most important sources that most Rust users learn from as consensus

  • sometimes you may want to dive into the implementation details, but don't know how to start, then turn to search engines for help

  • learn by summarizing and comparing

    • a good example of summarizing: Rust Iterator Cheat Sheet (from @DanielKeep heh), it describes the Iterator methods in the form of simple notations
    • write down the 3rd crates you see and compare: I used to do this to know why I need the crate as a supplement
    alternatives to data structures in std

1 Like

Some good suggestions there. Thanks.
I might add that I really don't understand why the Crust of Rust videos are so long! I wish someone would make something snappier. Maybe it's my lack of stamina...

It's funny you ask this because Jon has a (short!) video explaining the reasoning behind it:

TL;DR: The target audience is more experienced programmers and Jon wants to show what it's like to write Rust code for real, which is where you get valuable "experience". Shorter videos are great for teaching a single thing, but by their very nature those sorts of videos will have contrived examples and never stray from the happy path.


Funny. Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.