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

add try from methods

Open benmkw opened this issue 5 years ago • 2 comments

as described in https://github.com/rust-num/num-rational/issues/85

I went ahead and implemented From and TryFrom for all applicable types, not just floats.

This is a more detailed approach than the current FromPrimitive Trait which always returns an Option but some conversions can never fail so we can unwrap them.

benmkw avatar Oct 22 '20 22:10 benmkw

As far as I can see, this does not include any new tests for the added functionality.

vks avatar Feb 04 '21 16:02 vks

As far as I can see, this does not include any new tests for the added functionality.

Yes, I was unsure how much this should be tested, maybe a few lines which check the Ok and Error case would be fine because it does not really add anything, just exposes existing functionality differently.

I was using this as a fork and also needed the try_into counterparts so I could add those as well if you think this would be a good direction.

benmkw avatar Feb 06 '21 17:02 benmkw