Surprises with Rust's `as` (and Python division)

14 min read July 08, 2024 #rust #python #programming

I've updated this post to clarify some parts and add some more context and examples. Thanks to everyone who gave me feedback on earlier versions!

Coming to Rust mostly from higher-level languages, I've experienced surprising behavior when using as for type casting, and started to avoid it where I could.

In this post, I give quite a bit of background information, which I hope explains §why someone might want to use asin the first place, §why I recommend for newcomers to Rust not to use as, and what I prefer to use to convert between types instead. If you want to skip that background and go straight to the point, press §here.

...more