top | item 31653907

(no title)

gameswithgo | 3 years ago

I really enjoy some of the optimization details like when the memory overhead of Option<> can be elided completely. Other languages with Options will actually toss data up on the heap that doesn't need to be because it is in a Option and, or at the very least always take up a byte with the tag.

Details like this let you use the safer and more ergonomic solutions by default rather than having to worry if they are worth the overhead.

discuss

order

tialaramex|3 years 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.