rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
694 stars 131 forks source link

add `Debug` trait to `pub trait Num` #319

Closed hamirmahal closed 4 months ago

hamirmahal commented 4 months ago

fixes #318.

cuviper commented 4 months ago

Sorry, no, this would be a breaking change. I don't think Debug is fundamental to being numeric either.

hamirmahal commented 4 months ago

I understand. Are you also against pub trait Num implementing std::iter::Sum?

#[test]
fn test_sum() {
    use num_traits::Num;
    pub struct LengthNArrayOfTypeT<const N: usize, T: Num>([T; N]);
    impl<const N: usize, T: Clone + Num> LengthNArrayOfTypeT<N, T> {
        fn dot(&self, v: &LengthNArrayOfTypeT<N, T>) -> T {
            self.0
                .iter()
                .zip(v.0.iter())
                .map(|(a, b)| a.clone() * b.clone())
                .sum()
        }
    }
}

doesn't compile, but it could if pub trait Num implements std::iter::Sum, if I'm not mistaken.

cuviper commented 4 months ago

Any added requirements are equally breaking changes.