Hacker News new | ask | show | jobs
by devit 2164 days ago
Can we please deprecate the "as" operator?

Something so lossy and ill-conceived should not be a two-letter operator.

3 comments

It is possible, someone needs to do the RFC work.

I would say that my personal take of the temperature is "vaguely pro but not a slam dunk", at least from the opinions I've seen. Only one way to find out.

Then what do you propose for replacement? C++ style casts `(int) x` ?
into()/try_into() and methods designed for each of the other cases (e.g. truncate(), saturating_to_int(), approx_to_float(), etc.)
Using `x.into()` instead or `x.try_into()` if it can fail.
What would you suggest for replacing e.g. `u8 as usize`?
For this one, you could use From/Into, because it cannot fail. For numerics that can fail, TryFrom/TryInto.

The numeric casts are the easy part of this.