2 ms·
I wouldn't say so. I quite like "as". It can have sharp edges but I think the language would be significantly worse off without it.
by bigstrat2003 2y ago
I wouldn't say so. I quite like "as". It can have sharp edges but I think the language would be significantly worse off without it.
- zozbot234 2y agoThe question is not whether the language should include such a facility, but whether 'as' should be the syntax for it. 'as' is better than the auto conversions of C but it's still extremely obscure. It would be better to have some kind of explicit operator marking this kind of possibly unintended modulo conversion. Rust will gain safe transmute operations in the near future so that will perhaps be a chance to revise this whole area as well.
- wongarsu 2y agoIt's useful to have something that does the job of "as", but I dislike how the most dangerous tool for type conversions has the nicest syntax. Most of the time I want the behavior of ".try_into().unwrap()" (with the compiler optimizing the checks away if it's always safe) or would even prefer a version that only works if the conversion is safe and lossless (something I can reason about right now, but want to ensure even after refactorings). The latter is really hard to achieve, and ".try_into.unwrap()" is 20 characters where "as" is 2. Not a big deal to type with autocomplete, but a lot of visual clutter.