External Publication
Visit Post

Add something like `num_traits` to STD, or move it into std entirely

Rust Internals [Unofficial] April 19, 2026
Source

I generally prefer to try to use standard library traits than num_traits; in particular, for "numbers that support values 0 and 1" I have taken to using From<bool> which is standard and works for most types you'd want it to work for.

Unfortunately, this doesn't work so well with float types (but you might not want to be generic over those anyway, because float calculations generally need to be rounded and the details of the rounding frequently matter, but you can't take them into account when in a generic context).

The problem with adding extra traits is that existing number types in crates won't support them, so it tends to cause the ecosystem to become fragmented somewhat.

Discussion in the ATmosphere

Loading comments...