Hacker News new | past | comments | ask | show | jobs | submit login

Forcing people to explicitly casts everything all the time means that dangerous casts don't stand out as much. That's an L for rust imo.



The idiomatic Rust way to do conversions is using the From and TryFrom traits:

https://doc.rust-lang.org/stable/rust-by-example/conversion/...

https://doc.rust-lang.org/stable/rust-by-example/conversion/...

If the conversion will always succeed (for example an 8-bit unsigned integer to a 32-bit unsigned integer), the From trait would be used to allow the conversion to feel implicit.

If the conversion could fail (for example a 32-bit unsigned integer to an 8-bit unsigned integer), the TryFrom trait would be used so that an appropriate error could be returned in the Result.

These traits prevent errors when converting between types and clearly mark conversions that might fail since they return Result instead of the output type.


Thanks yeah I probably misremembered or misunderstood.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: