Top
Best
New

Posted by stmw 9/5/2025

A clickable visual guide to the Rust type system(rustcurious.com)
267 points | 41 comments
abricq 9/9/2025|
Makes me think of another Rust visualisation of the memory layouts, that I find amazing: https://johnbsmith.github.io/Informatik/Rust/Dateien/Rust-co...

Especially helpful if you come from C / C++

stmw 9/9/2025|
That's a nice one, hadn't seen it before for some reason
tialaramex 9/9/2025||
Note that the diagram of a Mutex is not how a Mutex works today, at least on reasonable platforms.

First, Mara changed it to be something much less silly, on Linux and similar it's a Futex, while on Windows it was an SRWLock. However, more recently (last year IIRC) the Windows Mutex is also basically a Futex, albeit Microsoft doesn't call their analogous feature a Futex.

In either case this futex-based design means there's no "inner" pointer, and nothing for it to point to, instead there's some sort of atomic integer type, when we're contended we go to sleep waiting on the integer via futex or similar OS feature.

Edited to add:: Also, the niche trick in the bottom right is somewhat broader than this suggests. If the type doesn't need every bit pattern then Rust might and in some cases is guaranteed to see a niche it can use for this memory optimisation.

Option<&T> is the same size as &T but also Option<NonZeroU16> is the same size as u16, Option<OwnedFd> is the same size as OwnedFd (and thus same size as a C integer by definition), Option<Ordering> is the same size as the Ordering (either of them) and Option<bool> is of course the same size as a bool.

ashvardanian 9/9/2025||
Was on the front page under 24h ago: https://news.ycombinator.com/item?id=45167401
stmw 9/9/2025|
OP here - yes, something didn't work with dup detection?, this one was submited days ago, before then one you linked and both ended up on the front page. Certainly not intentional.
Jtsummers 9/9/2025|||
If it had no or few comments, the dupe won't be treated as a dupe after some period of time. Then your submission probably ended up in the second chance pool and we get this situation. It happens pretty often.
Tade0 9/9/2025|||
I'm happy it was posted again because I missed the previous post and I happen to need this cheatsheet right now.
mattlutze 9/9/2025||
I love a page that doesn't react to my browser width.
titouanch 9/9/2025||
How this is structured reminds me of the periodic table.
pwdisswordfishz 9/9/2025||
Yeah, except this one is much more arbitrary in its choice of groupings and arrangement. Why is the boolean and Unicode scalar type in the same column as floating-point types? Why is the ! type not next to enums if () is next to tuples? (Both are neutral elements of their respective type-formation operations.) How is Sized to Drop as Copy is to Clone? You can go on and on. If you take the "periodic table" framing seriously, you can see some actual correspondences on display (like between plain operators and compound assignment operators), but they drown in a sea of spurious ones.

It's like infographics. Pretty visuals, but little to no insight.

SifJar 9/9/2025||
Given the title "Elements of Rust", I suspect that is very much intentional.
germandiago 9/9/2025||
That is nice. I absorbed a lot of understandable info in a very short time since I am familiar with some other statically typed languages.
phsilva 9/9/2025||
Reminds me of https://cosmic.mearie.org/2014/01/periodic-table-of-rust-typ.... Link not available to me, WBM has it https://web.archive.org/web/20240706045446/http://cosmic.mea....
oytis 9/9/2025||
I feel like I need a guide for the guide
worldsayshi 9/9/2025||
Does Rust not have built in Traits for string representations (like Show) or json representations of data?
dathinab 9/9/2025||
it has Display and Debug trait

both require a `fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>` function

while they work the same semantically it's "convert to string for displaying" and convert to string for debugging" (where debugging could be log messages, or print line debugging etc. by default debug for strings will do string escaping and for structs does print the structure/fields/type name in some semi standard way).

the Formatter is mostly just a string writer/sink, which also exposes a fixed set of formatting options and some utility methods

if a type implements Display through stuff I will skip over you then can also write `instance_of_type.to_string()` and get a string.

This trait are used in the default formatting mechanism used by e.g. `println!()` which other libraries (e.g. log) can use through `format!` and some other more internal/95% of case you don't need to know stuff. E.g. `println!("{a}, {a:?}, {a:#?}")` will in order print the display formatting of a, the debug formatting of a and then the alternative debug formatting (if there is one, else the normal one). And other options like pad left, floating point format options etc. exist too.

Through it should be noted that rust doesn't contain build in serialization, through nearly everything uses the library/traits/types from `serde` for that.

johnisgood 9/9/2025||
Only if Rust did not have so much symbol soup... :/ It is a bit too much for me, personally. If you are accustomed to it, it is probably not a big deal for you anymore, but for someone who does not know Rust as well, it could be a deal-breaker, which is why I would still rather prefer reference implementations in C, not Rust. Do not hide things from me!
tstenner 9/10/2025||
To be honest the few rust formatting options are easier to remember and more logical than the printf placeholders, e.g. ? for debugging, x for hex, X for upper case hex etc.
johnisgood 9/14/2025||
What does it have to do with Rust formatting options?

I am saying I much prefer reference implementations to be written in C, as it is pretty straightforward to understand, just like pseudocode would, but you can compile and run a C program.

bonzini 9/9/2025|||
String representations are obtained with the Display trait, which automatically results in an implementation of to_string() as well.
danielheath 9/9/2025||
Those are in (widely used) packages like serde
johnisgood 9/9/2025||
Someone mentioned a syntactic sugar for stuff like "let mut iter = a.into_iter();" (into_iter() bit) and the like, may I get reminded of them again?
zwnow 9/9/2025|
I like it, looks cool on desktop, but a mobile view would be cool to have as well. Having to scroll from left to right is a little awkward. Just as a side note
dxxvi 9/9/2025||
I agree. With a 1920-pixel wide monitor, I have to scroll horizontally to see everything.
orphea 9/9/2025|||
It looks like about 2110 pixels is the minimum window width at which the horizontal scroll disappears.
davsti4 9/9/2025||||
Ctrl-- (browser zoom down to 80%)
zwnow 9/9/2025||
Why would I do that if there is stuff like CSS where the dev responsible for the implementation could've built it responsive from the start.

Ironically this does not surprise me on a Rust based website.

johnisgood 9/9/2025|||
1280x1024, I have to scroll horizontally as well and it is quite annoying. It works at zoom level 50%, but the font is a bit too small, then. :P
WD-42 9/9/2025||
For all the rust programming you do on your phone?
zwnow 9/9/2025|||
There's absolutely no reason to not make a website responsive. Its even expected considering how little effort it takes.
Arch-TK 9/9/2025|||
It would slightly defeat the point of arranging it the way it is.

But I also don't think the arrangement is that useful.

stmw 9/9/2025|||
Nothing to do with the content, but not sure there's not reason - it seems a lot of responsive websites are low density and poorly formatted on desktop just so it is mobile-first. Just based on observations, doesn't seem like it's little effort for most people.
CodeMage 9/9/2025|||
I occasionally read about programming when I'm not programming. Some of that reading happens on my phone.
WD-42 9/9/2025||
Blogs sure. This is a reference. Seems silly to potentially compromise the UI for its primary purpose just so random people from HN can better read it from the toilet.
CodeMage 9/9/2025||
Is it a reference? It doesn't look like something anyone would consistently be reaching for. It looks more like a fun visualization of some core concepts, something you would show people as a cool thing you made.

Even if it was a reference, the same criticism about left-right scrolling would still apply, at least if you're using the combination of resolution and DPI that people like me do. In fact, if it's meant to be a reference, then it's even more important to make it ergonomic.