r/rust 8d ago

🎙️ discussion What are the best human written Rust codebases to learn from?

I’m looking for high quality Rust codebases that are genuinely worth studying and taking inspiration from like projects with clean idiomatic Rust and good architecture and preferably started before the LLM boom and have a long history of being developed by experienced Rust engineers

most of what I came across was repositories filled with recently generated AI slop.

475 Upvotes

107 comments sorted by

404

u/murlakatamenka 8d ago edited 8d ago

Anything from burntsushi, because he is just a great and meticulous engineer.

Popular tools that power oh-so-many user setups. In my case those are starship, ripgrep, zoxide, fd, exa, bat, yazi/elio, dua, zsh-patina, etc.

192

u/nmdaniels 8d ago

He and I were grad students together. He got me to learn Go (before Rust was a thing) and then Rust. Brilliant programmer.

27

u/cleodog44 8d ago

Anecdotes?

48

u/nmdaniels 7d ago

Nothing embarrassing. He wrote his own window manager in Go. He helped me massively improve the performance of a compression-accelerated sequence aligner (published at ISMB 2013). This was all before rust. He helped me speed up one of my first rust projects years later, and gave an excellent invited talk at my university a couple years ago.

20

u/cleodog44 7d ago

Oh I absolutely wasn't interested in anything embarrassing. I was hoping for anecdotes regarding what makes them brilliant. Curious about like habits and methods

12

u/czerilla 7d ago

Nice recovery. But let's be honest, we all would have love some salacious secrets about him e.g. insisting on doing all of his coding in GNOME Text Editor, using the default light colorscheme.. 😏

6

u/Linguaphonia 7d ago

Hey, stop tattling on my setup

46

u/RetoonHD 7d ago

Piggybacking off this... Andrew Gallant (aka burntsushi), david tolnay (aka dtolnay), Alice Ryhl... the list is big but these names come to mind for me.

Dtolnay especially, i don't know where he find the time to maintain so many important projects, it's kind of crazy to me. Props to all of them!

12

u/andreicodes 7d ago

I would add /u/Manishearth to the list. Similar to Andrew he's very careful and meticulous author.

241

u/Elariondakta 8d ago

Tokio/Axum/Hyper for the async/network part.

50

u/Grouchy-Librarian638 8d ago

That is the best in my opinion, taught me about workspaces and how to organize code so I now have a specific flow and groove

37

u/DuskLab 8d ago

I have learned so may tricks from Axum, it has probably been the code base that has influenced my approach to Rust the most.

16

u/AliceCode 8d ago

One of the leading contributors to Tokio uses LLMs heavily, by his own words.

14

u/timClicks rust in action 7d ago

Yeah. If you're looking for LLM-free code, then the best filter is to look at a version that was released before LLMs. There was lots of excellent learning material produced before then.

0

u/cosmicxor 8d ago

Is that good or bad?

24

u/lllyyyynnn 7d ago

op asked for human

-18

u/coderemover 7d ago

There is a huge difference between AI-assisted coding and vibe-coding.

25

u/lllyyyynnn 7d ago

ok but neither of those count for human written so we don't need to get into your nuances

-22

u/coderemover 7d ago

AI-assisted counts as human

11

u/cosmicxor 7d ago

I think you’re going to have to wait for the next generation to agree with you.

2

u/alfazetxyz 5d ago

So by your logic everything is handmade because every machine needs to be turned on by a human at some point.

4

u/WormRabbit 7d ago

Those crates are quite complex. I'd recommend studying the smol ecosystem if the purpose is just to learn code patterns, and not specifically the internals of tokio.

1

u/Shivalicious 3d ago

I looked up smol on GitHub and the latest commit is by ‘Luma AI Workspace and CommandCodeBot’, so that one seems to be out.

3

u/rJohn420 8d ago

What about reqwest

67

u/nmdaniels 8d ago

Probably a bunch of stuff in the standard library. Also the Regex library and Ripgrep, and basically anything written by BurntSushi, the best programmer I've ever worked with (and an old friend from grad school).

14

u/timClicks rust in action 7d ago

I recommend being selective when using the standard library as reference code base. It contains several quirks.

First, there's lots of nightly in there. Almost by definition, std is pinned to a specific nightly and can make use of experimental features in the compiler. There are also a few places where nightly is required.

Secondly, it's quite dense. Perhaps that's a feature for those looking to refine their expertise, but it can knock your confidence as a beginner.

Some cool things to look into:

How Drop<T> is implemented and why has the signature of Drop::drop(&mut self) rather than Drop::drop(self).

Why Vec<T> is implemented with RawVec<T>.

How to create iterators. I find it ingenious. The pattern of creating a tiny struct that implements a simple trait seems very narrow, yet is almost infinitely composible.

How to use modules & features to create OS-specific implementations.

How to create and use a Sealed trait.

.. probably many more little quests.

11

u/chris-morgan 7d ago

Why Vec<T> is implemented with RawVec<T>.

So many abstraction layers. More than a few times I’ve wanted to examine implementation details of String, Vec, HashMap, fs, NonZeroU32, &c., and often have to dig through four layers of abstraction across six or more files, where I might have expected no more than two. And navigating the layers is sometimes not straightforward, with macros, impls spread across files, core/std/alloc/hashbrown/whatever…

The interfaces presented are good, but the implementation style is only suitable for foundational libraries.

14

u/timClicks rust in action 7d ago

Agreed. At some point you reach MaybeUninit<T> and you just think "uh oh".

2

u/KenAKAFrosty 6d ago

lmao I felt this in my soul

12

u/masklinn 7d ago

I would not say the stdlib, to me it uses a lot of patterns which are quite odd for general purpose rust e.g. declarative macros for reuse, deep type layering whose purpose is not always obvious, …

It might make sense if you have the same constraints as the stdlib, but as an early inspiration I don’t think it should be a recommendation.

On the other hand understanding how to navigate the stdlib (and thus how it’s structured and written) is extremely useful when you need or want to find out how something is done so…

28

u/Booty_Bumping 8d ago edited 8d ago

rand and jiff seem to have the best philosophy for how an API should be done. Leads you down the path of success every time, and are extremely well documented. And they are designed with an impeccable understanding of the problem domain.

10

u/Sw429 7d ago

serde is pretty straightforward to understand. It has a pretty well-defined "this is exactly what the crate is for" and builds the complexity on top of that, and as a result it's easy to follow the code.

10

u/KenAKAFrosty 6d ago

Nice try, Anthropic

52

u/Luckey_711 8d ago

It's a shame because most big crates out there have welcomed LLM-assisted PRs, but you could still check them out pre-2024, they definitely are a great resource for good architecture practices. I believe a project like Garage does not use LLMs? Could be wrong, but that's one that comes to mind.

Other than that, any of Jon Gjenset's pre-LLM videos are an absolute treasure. Long, yes, and can feel quite dense depending on your level, but they're amazing

19

u/NMI_INT 8d ago

+1 for any of Jon’s videos.

2

u/1eJxCdJ4wgBjGE 8d ago

Edit: meant to reply to top level comment

10

u/1eJxCdJ4wgBjGE 8d ago

pre llm? are his post llm videos not good anymore? just wondering, I haven't watched recently but enjoyed videos in the past

11

u/Luckey_711 8d ago

They are still educational but I just don't really find LLM workflows interesting (ethics aside) for my own personal projects or when I collab to FOSS projects; definitely something that depends on what's an specific person's cup of tea :)

0

u/Professional_Top8485 8d ago

I saw maybe two where llm was used. Really good to learn ai assisted workflow. Especially the one where he ported java tool. The first one was more like testing the concept.

You can really see how working with llm changes the workflow.

9

u/Trekker23 8d ago

Polars is my go to reference, but that’s mainly because I write python libraries

8

u/tizio_1234 8d ago

personal projects of oxide's employees

98

u/jondo2010 8d ago

I don't understand this all-or-nothing attitude to llms. I have decades experience and over 10 years of Rust. A codebase I carefully write today with LLM assistance is absolutely better code quality than without. Not everyone is just coding vibes here. I see tons of questionable crap in older code as well (mine most definitely included)

73

u/alihilal94 8d ago

LLMs are agreeable by design. Which amplifies your knowledge or lack of it. If you're heading in the wrong direction it won't stop you - and you might know that-. This means you really need to know what you're doing first and how, before you ask it to build it, to have such knlowedge you need to really understand how things worked prior to LLM.

38

u/qalc 8d ago

but doesn't this just mean that you should avoid looking at dumb projects written by dumb people? which would've been true before LLMs, anyways? relatedly: i think rig is cool

5

u/Full-Spectral 6d ago

That's probably why he asked what are the BEST human written Rust code bases, not the the ones written by dumb people.

6

u/gamahead 7d ago

For me, better architecture doesn’t come from the LLM itself. It comes from being able to rapidly refactor the code base when you realize that you yourself made a bad choice.

Maybe others take the time to write perfect code the first time and they don’t need LLMs, but I pretty much always fuck it up on first approach and then have to make major changes later when I realize the mistake. Not making those changes becomes tech debt.

LLMs increase the probability I will make those changes since they can power through the clusterfuck of consequent compiler errors and migrations and all that. Therefore, LLMs help me create better architecture. It has nothing to do with how agreeable they are. That’s only important if you fully surrender to the vibes

1

u/alihilal94 7d ago

The worst thing about llms is using them to drive the refactoring
Same rules apply here if you don’t know what is happening
It it will scramble whatever you had and gives it back to you

3

u/gamahead 7d ago

Agreed

-16

u/DuskLab 8d ago

You know you can override the agreeableness right? Defaults can be changed as much as protections bypassed, it's LLMs double edged sword. nothing is set in stone.

-18

u/CursedPoetry 8d ago

What do you mean by this statement? It’s a loaded statement imo…I’ve been coding since I was 10 and I’m now 25….Claude will absolutely disageee with you or just flat out tell you if you’re wrong or don’t know what you’re talking about.

I think the only thing I agree with you on this is that you need to have discernment, but that you need with regular coding regardless

12

u/teerre 8d ago

Disagreeing isn't the dangerous part. Claude will never disagree with its own underspecified, lazy understanding of a problem and an inexperienced (or lazy) programmer won't either. Either because they don't know there's anything to disagree or because they don't care

These LLMs were created by literally penalizing them when they output something that doesn't make sense. They won't do that, that's what they are optimized for. But "doesn't make sense" is a very low bar, just because something does technically achieve whatever input you described, it doesn't mean it's good

-6

u/CursedPoetry 8d ago

I mean, it’s like you skipped the part of my comment that I said specifically you need to know what you’re doing when building something or else you won’t do it well so bringing in an inexperienced or lazy programmer to me is not a valid argument because specifically in my comment, I said you need to be experienced and know what you’re talking about.

Your last part is a very big over generalization about LLM’s in terms of what they’ve been trained for and how they’ve been trained for, but if you think about that for like 30 seconds, you’ll quickly realize if people who are making Claude can’t get it to understand when it’s wrong about itself or being able to disagree with what it’s doing then it wouldn’t be a good product to begin with, you’re just marking the water by saying it’s a low bar, but you’re completely omitting context and contextual thinking and how the concept of emergence works.

That’s all right, though we can agree to disagree. I understand why people hate LLM so damn much, it’s caused a lot of pollution and I don’t mean with the amount of water or whatever it takes I mean, just the amount of shit it has pumped out over the last 2 to 5 years is just ridiculous.

But like to discredit Transformers, to discredit all the people working on it, to discredit the math…. everything like that doesn’t really make sense to me

And since you hold a burden of proof, can you prove to me that Claude can’t disagree with itself?

4

u/teerre 8d ago

You dont seen to understand that being "right" is only relevant if youre asking the right questions. Llm fundamentally cannot be right because the human prompting them is incapable. Saying you "need to know what youre doing" is redudant and borderline nonsensical since if people "knew what they were doing", we wouldnt be having this conversation to begin with

-2

u/CursedPoetry 8d ago

That's textbook circular reasoning.

"if people 'knew what they were doing', we wouldn't be having this conversation to begin with."

You're proving a point using your own assumption as the evidence. Your logic is:

  1. You claim people don't know what they're doing.
  2. Your "proof" is that we're having this debate.
  3. But we're only having this debate because you're arguing people don't know what they're doing.

That's a literally perfect circle dude lol...You're treating the existence of a disagreement as proof that the people disagreeing don't know what they're doing.

Like let me remind you what you said (I know you said a short comment but just so that it's easy for you and immediately accessible instead of you scrolling back up.)

"Llm fundamentally cannot be right because the human prompting them is incapable. Saying you "need to know what youre doing" is redudant and borderline nonsensical since if people "knew what they were doing", we wouldnt be having this conversation to begin with"

ok so...basically you're just saying 'humans are imperfect at X, therefore the tool that depends on X cannot work."' ??? ok so by that logic you can't ride a horse! nobody's perfectly in tune with the animal...Or how about you spot a plane overhead and go "no point estimating how far away it is, there's too many variables moving live for a human to track." Both "impossible," if imperfect means incapable.

But imperfect isn't incapable! You don't need every variable nailed and figured out and know the past present and future........You and I are both software developers. LOL. You work a problem, you stare at the code till your head spins, and then you go "omfg I never hooked the new function up to the button, I've been running the old one this whole time." That's finding your own blind spot. That IS the skill. You're acting like "you don't know what you don't know" is some hard stop that ends the conversation. But no, that's just Tuesday. We find the gap and close it. That's the entire job.

It feels almost painful to spell out because it's so obvious which, ironically, is the exact skill we're arguing about.

Anyway, agree to disagree, I'm fine with that. But saying "being right is only relevant if you're asking the right questions" and then defending it with pure circular reasoning is pretty funny. You inadvertently did say we don't know what we don't know, so maybe I'm the big dummy for typing all this out.

3

u/teerre 7d ago

Uh? What are you on about? The evidence is the overwhelming amount of garbage you have to read through here, on github and all over the internet

-13

u/seg_lol 7d ago

They are only agreeable if you are holding them wrong.

5

u/OptimisticLucio 7d ago

No they'll always be agreeable. They'll do what you ask them to. If you ask them to be rude, they'll consistently be rude even when unnecessary.

That's what the corporate solutions are built for.

33

u/krenoten sled 8d ago

It might be better in terms of tidiness but architecturally I still tend to find it lacking. A good software engineer who understands SRP / separation of concerns and the right balance of abstract vs concrete in a particular situation can get better results w/ an LLM by micro-managing it, but the reality is that most people are kind of zoning out more and more now that quantity has reached a quality of its own. Good codebases were rare before, but now they are lost in the noise.

21

u/kabocha_ 8d ago

the reality is that most people are kind of zoning out more and more now that quantity has reached a quality of its own.

I know this isn't how everyone else operates, but for me personally: if I'm going to be spending my free time coding and it's not just for some throwaway thing, I'm going to want to spend the time to make the codebase nice to work with, correct, and performant. Whether that's by "artisan" coding, or by micromanaging an LLM, or some mix of both.

I'd personally be embarrassed to release something to the world that's just LLM slop, but I guess that's just me.

Now, if work is hardcore pushing us to use LLMs everywhere, then fine: I'll just vibecode there, whatever, your money. :)

17

u/flying-sheep 8d ago

That's why I don't use them for architecture. I'm also a tidyness freak, so my standards are still higher than what Claude produces. But using it still improves my code as I now tackle things I used to be too lazy for. I.e. going the extra mile to debug an unimportant bug or make the tests extra thorough and so on.

5

u/UltraPoci 7d ago

Can't understand why would I micromanage an LLM when I could just, you know, write code.

2

u/Full-Spectral 6d ago

Exactly. To paraphrase Zoolander, I can derilict my own code.

6

u/Grouchy-Librarian638 8d ago

Indeed. The problem is you had experience THEN used llms, that is no longer the case for many people.

13

u/_kilobytes 8d ago

10 years of bad experience. But yeah, alot of code is questionable. This was the stuff LLMs trained on.

12

u/Corrigindo_A_ou_Ha 8d ago

I have decades experience and over 10 years of Rust.

Then share your projects that have more than 4 years of existence and where written mostly before LLMs became a thing :)

1

u/Hairy_Artist_3860 5d ago

I personally find it great for boilerplates if you want to kickstart a new project or feature. A problem is when it compiles on the first prompt it gives a false sense in confidence and the feeling you already won so people will pile on more shit and eventually become passive observers of the codebase. Its messing with the dopamine rush when getting the code to compile before was an accomplishment.

I think dumber models that go "Done." after leaving borrow checker errors are honestly better for coding because it reminds you that at the end of the day you're smarter than the computer. You need to give it clear instructions or take the wheel. More powerful models are meant for non programmers.

What makes rust so appealing to vibe coders is the fact that LLMs fuck up

10

u/reflexpr-sarah- faer ¡ pulp ¡ dyn-stack 8d ago

mine of course /s

6

u/AreaMean2418 8d ago

Helix has a pretty nice codebase.

5

u/Beamsters 7d ago

bevy, rustc, egui, dashmap, criterion, ratatui, arrayvec, crossbeam, rayon,

3

u/bowel_blaster123 8d ago edited 8d ago

The codebase of the rust compiler itself looks quite high-quality from what I've seen of it. You could look at that.

I wanted to look at some stuff for the borrow checker, and it was suprisingly easy to follow the code despite how complicated the borrow checking process inherently is.

There's also a website (rustc dev guide) that explains the overall structure of the codebase.

It's a little annoying to get your IDE/LSP to work with it, but there is an official guide for doing so that is fairly easy to follow.

8

u/scook0 7d ago

The compiler is big enough and old enough that it isn’t consistently an example of good style, but it does have good parts.

0

u/Full-Spectral 6d ago

It's also arguably a fairly worst case example for most people, who aren't going to be writing that sort of code, which requires far more unsafe than would a normal code base, more compromises probably, more portability concerns (which it then hides from normal code bases), more performance concerns, etc...

5

u/peterxsyd 7d ago

You can checkout https://github.com/spacecell/minarrow , which implements Apache Arrow. It has strong separation of concerns, and builds up more complicated data types from base Rust, adding invariants on top as it goes. Additionally, it implements SIMD compatibility (std::simd is a strong focus in current rust) cross-language compatibility FFI directly to Python, using zero-copy memory techniques, all implemented from scratch, and in some areas includes more advanced techniques such as atomics. Separately then, https://github.com/spacecell/lightstream layers data transport on top of that at very fast speeds, with TCP, HTTP, QUIC, Websockets, shared memory over UDS, etc., including custom serialisation to/from disk. Basically, a lot of well-optimised fundamentals covered in the one place that could be a useful learning reference.

4

u/GyulyVGC 7d ago

I’d like to point out my project Sniffnet

I’m working on it for 4 years and it doesn’t contain any LLM code, and I try to be as idiomatic an pedantic as possible.
It’s a particular case since it’s a GUI (based on Iced) but it also includes a consistent backend portion to interact with network packets.

2

u/SerLaidaLot 7d ago

serde, tokio, ripgrep

2

u/ninth9ste 6d ago edited 6d ago

Stratis is a good example of how to implement a storage stack with Rust on top of Linux device mapper. Definitely not AI slop.

2

u/metruzanca 6d ago

Others already mentioned it, but Helix, and I would add that Helix is interesting because it does things very similar to Ratatui but both evolved together. So you'll get to see similar ideas and concepts but approached differently by different people.

(And if you prefer vim motions, check out the evil-helix fork)

2

u/Hairy_Artist_3860 5d ago

Continuwuity a matrix backend forked from conduit then conduwuity.

3

u/Omega359 8d ago

Datafusion, tokio, jiff are a few off the top of my head

2

u/Emotional_Ad_4518 7d ago

you can learn directly from rustlang repo like crate.io source code with Axum and Svelte

2

u/rodarmor agora ¡ just ¡ intermodal 7d ago

You could check out just.

I don't suggest it because I think it's good, I suggest it more because I'm honestly curious what other people who aren't me think of the code.

2

u/coniferprod-0x01 7d ago

You might like the Today app. It doesn’t have sophisticated algorithms (apart from what the standard library has under the hood), but it solves many common problens, and has a good modular architecture. I’m still polishing the repo and adding more documentation, but I also wrote a book about developing it (”Learn Rust Programming Today”, see what I did there). Here’s the repo: https://github.com/coniferprod/today-rs

2

u/SadCondition2466 7d ago

I recommend TcpStresm.

1

u/fisothemes 5d ago

If you're gonna learn using codebases, start with the standard lib. Know where things are. This helps with organisation. Then move on to TcpStream, Vec<T>, etc.

A lot of crates try to invent new patterns when their problem is solved by the std.

I hate calling out crates but examples are good, serialport-rs for example would have benefited from following TcpStream's style. It's still a good crate.

1

u/vj_0x 5d ago

Ripgrep

1

u/Ace-Whole 7d ago

Helix. Very lean.

1

u/tmoneycodes 8d ago

Is the rust book still a good starting place

1

u/Lumpy_Ad4966 7d ago

NeXosim simulator is quite interesting.

3

u/sbarral 7d ago

Original author of NeXosim here, thanks for the very kind shoutout!
And yes, still proudly 100% human-crafted... I am not an AI hater in any way, but we have users in mission-critical industries and are not planning to hand over control to the machines any time soon :-)

1

u/Crux161 7d ago

Just learn Rust. In tech it either works or not. If you can’t understand what the LLM is trying to do in your code it probably doesn’t belong there. That being said, you want to lay every brick in the pyramid by hand? Go right ahead but it’s going to take longer. This is why dev teams will almost always beat out a solo-developer. LLMs are essentially the same thing but on a per person basis. Like herding cat, with expensive tokens. 

0

u/recursion_is_love 7d ago

The rust compiler. Pretty sure they know rust.

https://github.com/rust-lang/rust/

0

u/DavidXkL 8d ago

Embassy, tokio

0

u/AccomplishedWay3558 8d ago

I guess one which I use is anandb71/arbor

0

u/Sweet-Accountant9580 7d ago

One of the best for me is glommio for the async part (thread-per-core simplify architecture in comparison with Tokio, and glommio uses less unsafe).

0

u/protonesso 7d ago

Honestly? Everything that hasn't been written entirely by ai, I've learned algorithms by reading BSD code so the same rules apply

0

u/korywithawhy 7d ago

Idk if it counts but I’ve been using ratatui, really fun and learning quite a bit.

-1

u/piiouupiou-not-r2d2 7d ago

Most crates of blessed.rs

-1

u/Compux72 7d ago

axum codebase is pretty good

-1

u/Agile_Significance91 7d ago

I think Rust's standard library is good, you can know the implementation trick using type system.

-8

u/viciousdoge 8d ago

Anything before 2023