1. 28

What are some of the best repositories in the wild for beginners to learn Rust by reading through the source code?

Looking for something that doesn’t use too many external crates, and mainly relies on “vanilla” Rust.

Thanks :)

  1. 16

    I would say in general it’s not possible to learn a programming language by reading code.

    The only way I’ve found to learn a language is to use it to develop something - even if it’s something nobody else is interested in, or it’s re-inventing a wheel. You’ll learn more in a week of writing code than you will in a year of reading it.

    If you get stuck or can’t figure out how to use a feature or library, then search GitHub or search the web and look for examples.

    1. 1

      That makes sense. Maybe new learners should look for projects.

    2. 13

      Anything written by BurntSushi.

      1. 6

        The smol asynchronous runtime is just one file. It is mostly comments. I believe it is intended for pedagogy.

        1. 2

          smol is definitely not meant for pedagogy. It’s the third successor of the async-std runtime.

          1. 1

            Ah, my mistake.

            1. 2

              Not a problem, I think it’s a great mistake to make and speaks about the quality of the docs!

        2. 4

          For the very basics, here’s an ultra-simple CLI tool that basically just hooks up some existing code to a command line interface.

          1. 1

            I’m curious what other people who haven’t use Rust think of the syntax and it’s general feel. I get what’s going on, but there’s something syntactic I find repellent (but I can’t put my finger on it – it’s not like parentheses in Lisp), and was wondering if it’s just me.

            1. 2

              but there’s something syntactic I find repellent

              Purely guessing here because it’s hard to know your tastes without knowing your PL history, but often what I see people react to if there’s nothing specific they can point to is the expression instead of statement focus - implicit returns, assigning to an if/else or block expression, etc.

            2. 1

              I’m not familiar with Rust, but all those for loops look more like Go to me — is that really idiomatic?

              1. 1

                For loops aren’t inherently bad - I find them more readable than a long iterator chain in lots of cases where there’s a large body, side effects, etc. One thing I like about rust is that it doesn’t lock you into either loops or hofs.

                That said, the trues function is a good example of something that would likely be more legible as a filter and count.

                Edit: in general I think CLI arg parsing code won’t be a great intro example for any language though. It’s almost always going to be a large wad of conditional blocks and not very interesting or representative.

                1. 1

                  I didn’t mean to imply that for loops are inherently bad — you give some valid examples.

                  I would, though, have expected Rust to have something like .contains() to check for a true value in a collection.

                  1. 1

                    Rust collections do have .contains(), and so does slice, so it is widely available. Iterators also have a variety of functions to filter / map / collect values, so if you don’t want to use a for loop then you don’t have to.

            3. 2

              Not saying it’s 100% idiomatic, but I started writing a CLI password manager which I hope is quite easy to understand: https://github.com/stchris/passage

              1. 2

                What about these koans, Build your own JIRA with Rust?

                1. 1

                  Motivated by re-reading Gabriel’s Patterns of Software, I have recently been reading the 2.x branch of clap. It has a reasonably small number of dependencies (especially if you don’t count the optional ones), it’s a useful non-trivial library so it might pay up to be more deeply familiar with it, and I found it to be fairly straightforward to follow.

                  I can’t really say it’s been life-changing so far, but I’m still exploring it and I’ve picked up a few interesting tidbits I’ve used in my day-to-day work. It’s very useful to see how other people structure their code and approach readability.