num-traits icon indicating copy to clipboard operation
num-traits copied to clipboard

Introduce derive macros

Open baboon25 opened this issue 1 year ago • 1 comments

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>{}

baboon25 avatar Mar 07 '24 15:03 baboon25

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

cuviper avatar Mar 07 '24 19:03 cuviper