|Supported as of 0.10|
This "periodic table" is a cheatsheet for various Rust types. Rust programming language has a versatile type system that avoids a certain class of memory error in the safe context, and consequently has somewhat many types at the first glance. This table organizes them into an orthogonal tabular form, making them easier to understand and reason. I also hope that this makes very obvious why Rust needs such seemingly many types.
The periodic table was made by Kang Seonghoon as a thought experiment, and then... it have got redditted unexpectedly :p Henceforth I've made the URL permanent and added some descriptions. Some post-reddit changes include:
[T, ..n], so it has a new "unsized" column now.
T) occupy two cells since you can use trait methods to those types. Also proposed function traits are updated and some of them are marked impossible as per the comments by glaebhoerl. Thanks everyone in /r/rust and #rust-internals for suggestions!
Discussion: /r/rust, /r/programming, Hacker News
Columns indicate the ownership. There are two big groups from left to right: indirect (i.e. pointers) and direct. Particularly indirect types can be coerced horizontally:
~T can be coerced to
&mut T or
&mut T can be coerced to
Rows indicate the different kind of types. There are three big groups from top to bottom: unsafe dereference, safe dereference and callable.
Colored backgrounds (sorry the accessibility!) indicate the current availability. Black background means the type is plain absurd and prohibited. Gray background means the type makes some sense but it is not yet in the language. Fortunately we have two proposals that cover all the missing types now:
Traitdo not have their size known in the compile time. The proposal allows them in the limited context, and that is primarily useful for fully supporting custom smart pointers. This also has a side effect that allows for
&mut str, though it won't see much use since safe strings cannot be modified via indexing.
There are some optional syntactic parts possible in types. Many of them are turned off by default since they are normally verbose, but you can turn them on if you want.
Copyright © 2014, Kang Seonghoon. This work is licensed under a Creative Commons Attribution 4.0 International License.a part of cosmic.mearie.org.