External Publication
Visit Post

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

Rust Internals [Unofficial] April 18, 2026
Source

For generic number implementations in std::num, as @CodesInChaos pointed out in this comment for the case of complex numbers, num_traits would make implementations significantly more flexible, and (in my opinion) much easier. For example, it would be much easier to implement a (hypothetical) complex sine function just like this:

impl<T: Float> Complex<T> {
    fn sin(self) {
        Complex::new(sin(self.re) * cosh(self.im), cos(self.re) + sinh(self.im)
    }
}

instead of expanding over multiple implementations. Also, if this were made public, it would allow people to write their own implementation of Float and use std types with their definition of Float (for their own purposes).

A similar type already exists (core::simd::num::SimdFloat), which could be considered prior art.

Discussion in the ATmosphere

Loading comments...