←back to thread

Pitfalls of Safe Rust

(corrode.dev)
168 points pjmlp | 3 comments | | HN request time: 0.244s | source
Show context
woah ◴[] No.43603395[source]
Is "as" an uneccesary footgun?
replies(4): >>43603560 #>>43603887 #>>43603998 #>>43605135 #
1. bigstrat2003 ◴[] No.43605135[source]
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.
replies(2): >>43605381 #>>43605444 #
2. zozbot234 ◴[] No.43605381[source]
The 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.
3. wongarsu ◴[] No.43605444[source]
It'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.