Open benmkw opened 4 years ago
TryFrom
seems fine. It will need to be tested for compiler support, but you can see how num-bigint
did that.
I think arithmetic between rationals and floats is a lot more problematic, so I'd rather leave that to explicit conversions.
Ok I see seems like I should be able to basically do exactly the same using cfg attributes and just forward to the FromPrimitive methods. The Results Error type would be empty though as they only return an Option.
I added methods for converting from ints as well (some require try_from
/ some can be done through from
as they should never fail). In some generic code I'm currently using them as they make it a bit less noisy.
Maybe you can take a look and say if this is too much or seems appropriate?
Can TryFrom be implemented as well as FromPrimitive? This would make it easier to make conversions using
.try_nto()
.I would further propose to allow performing arithmetic between rationals and floats although this would mean that
From
would make more sense thanTryFrom
and errors would panic instead of returning an error.