Are casts encouraged in Rust?
Are casts encouraged in Rust?
Posted Jul 2, 2025 20:32 UTC (Wed) by alx.manpages (subscriber, #145117)In reply to: Are casts encouraged in Rust? by epilys
Parent article: How to write Rust in the kernel: part 2
Posted Jul 3, 2025 11:54 UTC (Thu)
by farnz (subscriber, #17727)
[Link]
There's thus a lot of design work in getting this right; it's OK if the initial solution only solves for some of these problems, as long as it doesn't block off useful bits of the design space for other solutions. I'd thus expect that we'll have a decent solution to the first problem - traits usable in const and non-const contexts if they implement a function as const fn, but only in non-const contexts if they implement it as fn - long before the other 2 get solved, because it's the lynchpin on which the other two stand - and indeed, work on this is actively happening, leading to an early design that's being pushed around until people are confident that it's a good design.
Casts are a known problem, and (AIUI) people are working to make the "as conversions" clippy lint a warn-by-default lint. There's some issues to resolve before we get there:
Casts are a known problem