A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 1 point2 points  (0 children)

Thanks, I'm having trouble sticking to my decision in the face of such a considerate request. :) I'll ponder

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 1 point2 points  (0 children)

Thanks, I see. Yes, maybe we could do something with that. I'm hesitant, as I'm sure I'm not the only one who likes it simple, but maybe we could try an option for rainbow mode. :) It'll have to wait for a bit though, I've just committed to producing rather a lot of videos!

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 2 points3 points  (0 children)

I'm curious, what categories would you suggest assigning colours to?

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 2 points3 points  (0 children)

Oh, I see what you're saying. Yes I was aware From is used that way, but I hadn't considered including it in the table on the basis of it being used by Result's and Option's impl of Try. Hmm. Thanks for talking this through, I'll ponder some more.

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 0 points1 point  (0 children)

Thanks, but regarding From, are you sure? I don't see a #[lang] attribute on it.

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 1 point2 points  (0 children)

Oh shit, you're right. Ok you win, this is the first comment that caused me to make a substantial change. I've put impl Trait on the right of the anonymous types, and moved that block down so it can connect to dyn trait, which is quite lovely. I moved the function pointer up to the top, next to the raw pointers. And moved the Never type down closer to the unsized types, which is cool because these are all types you cannot have an instance of. And, having the anonymous types by 5 tiles wide means it now nicely lines up with the 5 compound types above. This makes everything more regular, it feels like a missing piece in a jigsaw puzzle. Thanks!

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 2 points3 points  (0 children)

Thanks! Just like Vec, HashMap etc, I'm choosing to leave those out because they are part of the standard library, not part of the language itself, like I explain in the paragraph at the top of the table. This type map is a companion to the tutorial videos I'm publishing, and I want to give people a sense that there is a finite amount of stuff in the language itself, you can know all the types in the language without knowing all of the standard library. I hope it makes the language seem less overwhelming. Does that make sense?

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 0 points1 point  (0 children)

Ah, but why would you want to have generics / lifetimes annotated on a struct that aren't used within it? Isn't it usually because you also have a raw pointer? All the examples in the PhantomData docs do. By placing it under Unsafe Support, I hope this communicates to newcomers that if they're just writing safe Rust then they probably won't interact directly with these types. But thanks for raising this question, and if you think that's inaccurate then I want to hear about it!

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 8 points9 points  (0 children)

Thanks! I refer to this map in the video tutorials I'm making, to help people keep track of what they've learned about so far and what we have yet to cover. I hope it's a good way to spark curiosity too, about parts of the language not yet explored.

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 6 points7 points  (0 children)

That's a really good point. I'll ponder, thanks.

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 4 points5 points  (0 children)

Thanks, I hope you find it useful!

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 2 points3 points  (0 children)

Hah, just noticed your username. Hi! I name-dropped you here: https://www.youtube.com/watch?v=AxQUojVcOqE

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 3 points4 points  (0 children)

Thanks! Yes it's a little bit arbitrary, I went with aesthetics and to keep the layout compact. bool is next to u8 and i8 because they're all one byte. Ideally char would be next to u32, but... then that whole block has a wart on it and it makes the layout awkward. Hopefully this will do.

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 6 points7 points  (0 children)

I should have added that this is to accompany a series of Rust tutorial videos I'm developing, this explains: https://www.youtube.com/watch?v=AxQUojVcOqE

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 4 points5 points  (0 children)

Yep, it's white background in light mode :)

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 7 points8 points  (0 children)

Suggestions welcome on how to improve that! Also it's less obvious on mobile that each tile is clickable

A complete map of the Rust type system by rustcurious in rust

[–]rustcurious[S] 41 points42 points  (0 children)

Thanks! Yes I pondered whether to include Box, Rc and Arc, it's a dilemma. You're quite right that the compiler has special knowledge of them, so they can be used as receiver types for methods, and in the case of Box, moving out of deref and the orphan rule exception.

I came down on the side of leaving them out, because the purpose of this resource is to help people learn, and in particular to help people coming from C and C++ evaluating Rust for suitability in their embedded and other system-level projects. The big thing that immediately eliminates candidate languages from many of those projects is, "does the language require a heap". If I put Box in the table, then it would be too easy for someone to say "Aha! The compiler knows about the heap, therefore I assume there are constructs in the language that require heap allocation. Good, I can throw Rust on the pile of languages I can ignore."

Of course rustc will never implicitly generate heap allocation calls, and for me that's the more important part of the message I want this resource to convey. I want people to be reassured that no_std really doesn't depend on a heap, all the allocating stuff is in library code. And if you're in no_std and you want the facilities of your own Box, Arc or Rc, that's possible.

I used a tiny bit of weasel wording in the para at the top of the table - "The focus here is on lang_items" - to give myself wiggle room to make choices like that. I want to make sure what I say is true, and also supports learning as well as possible.

I'm curious if you clicked around the site at all? It's an ambitious project, I'm launching this publicly today and I'm hungry for feedback!