Rust Types - Taxonomy

By Nikita Bishonen • 5 minutes read •



Hello! Today I’m sharing my thoughts on type taxonomy in Rust. This is the first version of the taxonomy and post, and I’d be grateful for any ideas to improve it.

Taxonomy

Taxonomy (from Ancient Greek τάξις — arrangement, order and Ī½ĻŒĪ¼ĪæĻ‚ — law) — the doctrine of principles and practice of classification and systematization of complex organized hierarchically related entities.

I wanted to decorate my study with a graphical illustration of the ā€œtaxonomyā€ of the data type system, similar to what Rust uses. Unfortunately, my searches didn’t yield the desired result, so I decided to create my own illustration and share it with you in this publication.

Types

Theories

There are many theories, some of which are conditioned by the history of the development of computer science, others have real practical value and theoretical justification. I’ll provide links to two popular theories from both categories:

But I won’t try to delve into details since I understand them with difficulty, let alone the ability to explain them.

HoTT

Type Theory and Rust

The main question I was looking for an answer to is the type theory behind Rust and its projection onto the types we use when writing Rust code.

I’m not the only one asking this question: https://users.rust-lang.org/t/practical-intro-to-type-theory/18204/5

There’s also a small presentation on this topic: https://av.tib.eu/media/52178

ā€œMental modelā€: https://ia0.github.io/unsafe-mental-model/type-theory.html

And an interesting post: https://www.kurtlawrence.info/blog/category-theory-with-rust-pt1

But they all have lots of text and don’t have a ā€œcomprehensiveā€ chart that I could hang on my wall.

Rust Types Taxonomy

Taxonomy

Ultimately, based on my knowledge of theory, I created the first version of this taxonomy. I really love using trees (especially binary trees) to build hierarchies, as I find it easier to navigate and understand their essence. The visualization itself is, of course, the goal of this publication, but for interested and inexperienced readers, I provide some explanations and links below.

P-type

Product type - no, that’s not it. We combine several types into one, obtaining the product of possible values of these types as a new set of values. Which types in Rust implement it?

Ī£-type

Sum type unlike the P-type, a sum type provides stricter control over possible values of used types.

Pointer types

Rust has capabilities for working with memory, so the language contains both references and pointers. What interests us are only the ā€œhigh-levelā€ concepts.

Other types