3 ms·
Indeed. Also more broadly Rust's types do not exist at runtime, and so you get the New Type idiom. If we care about the difference between a Row and a Column in
by tialaramex 4y ago
Indeed. Also more broadly Rust's types do not exist at runtime, and so you get the New Type idiom. If we care about the difference between a Row and a Column in the program, we can create distinct Row and Column types, and Rust won't allow you to use a Row when you need a Column, even if they're both "just integers", yet at runtime there's no cost for this, if the obvious representation of Row and Column is a 32-bit integer that fits nicely in the general purpose registers and takes up 4 bytes of RAM, that's how they're both represented at runtime.
You can do a lot of this in languages like C++ but there are some pernicious limits that Rust didn't have e.g. C++ can't conceive of Zero Size Types.