greyblake / nutype

Rust newtype with guarantees πŸ‡ΊπŸ‡¦ πŸ¦€
MIT License
1.41k stars 23 forks source link

Feature request: Add derived implementations for `num` traits #3

Open RoastVeg opened 1 year ago

RoastVeg commented 1 year ago

Although num traits are usually implemented rather than derived, the num-derive crate shows that it is possible to write derive macros for them even for types more complex than newtype constructors.

In fact, with the constraints this crate can offer on new types, it would be possible to even derive traits like num::Bounded.

greyblake commented 1 year ago

Hi, thanks for reporting the issue.

I think, even if the lower/upper bound is not set explicitly in the validation, in that case MIN or MAX constant can be used of a particular inner type.

I guess, it must be technically possible to do, although it won't be my focus in my nearest future.

@RoastVeg Meanwhile, could you please share more details on your motivation and how would you like to use num::Bounded ?