Are casts encouraged in Rust?
Are casts encouraged in Rust?
Posted Jun 29, 2025 20:29 UTC (Sun) by epilys (subscriber, #153643)In reply to: Are casts encouraged in Rust? by alx.manpages
Parent article: How to write Rust in the kernel: part 2
They make sense in a lot of usecases, plus they are opt-in/explicit, so they are neither encouraged or discouraged in my (humble) opinion. If you make a mistake with casts, it's basically yet another logic bug.
The good news is that if you wish to not allow them in your codebase, you can use lints like `clippy::as_conversions` and deny them globally: https://rust-lang.github.io/rust-clippy/master/#as_conversions
