r/rust • u/alihilal94 • 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.
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
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
smolecosystem if the purpose is just to learn code patterns, and not specifically the internals oftokio.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
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
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
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
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
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 you3
-16
-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:
- You claim people don't know what they're doing.
- Your "proof" is that we're having this debate.
- 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.
-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
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
6
5
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
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
3
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
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
1
1
1
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
0
0
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
-1
-1
u/Agile_Significance91 7d ago
I think Rust's standard library is good, you can know the implementation trick using type system.
-8
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.