rust-num / num-traits

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

Introduce derive macros #312

Closed BabaBert closed 4 months ago

BabaBert commented 6 months ago

I think it would be quite neat to have derive macros for all num-traits and this shouldn't be breaking.

Use cases would mostly to write simple wrappers as such to make trait implementations easier down the line, but there could be other benefits from this as well:

#[derive(Float, FloatCore)
struct Float<F>(F) where F: Float + FloatCore;

#[derive(PrimInt)
struct Integer<I>(I) where F: PrimInt;

trait Foo{}

//not necessary to implement f32, f64 directly
impl<F> Foo for Float<F>{}

//same here for u8, i8, u16, ...
impl<I> Foo for Integer<I>{}
cuviper commented 6 months ago

We do have num-derive, but not for generic types, as there are some open questions: https://github.com/rust-num/num-derive/pull/37