Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One of the things the author neglects is the ease of use of newtypes in Rust. This can actually alleviate a lot of parsing issues, by making it impossible to use stuff without parsing.

An example of where I've recently done something like this is my sparse linear algebra code. I have distinct types for column and row vectors for a matrix, so that if I want to right-multiply A with a vector, the input has to be a column vector and the output has to be a row vector. Similarly, if I want to left-multiply A with a vector, the input has to be a row vector and the output has to be a column vector.



Maybe Rust makes newtypes _easy_, but certainly C supports similar idioms by way of wrapping data in a unique struct.


The only significant difference is that you have to give the inner value a name in C, but you don't in Rust. It's a pretty marginal advantage.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: