Are casts encouraged in Rust?
Are casts encouraged in Rust?
Posted Jun 30, 2025 19:29 UTC (Mon) by iabervon (subscriber, #722)In reply to: Are casts encouraged in Rust? by alx.manpages
Parent article: How to write Rust in the kernel: part 2
I think there's a different set of considerations for compile-time constants than for runtime casts; having "const x: u16 = 65536 as u16;" (or some other syntax for it) shouldn't result in an executable that unconditionally halts immediately with an error message, it should result in a compile error because that's not a sensible way to make a constant 0, but it also can't do anything else.
