rust-num / num-rational

Generic Rational numbers for Rust
Apache License 2.0
144 stars 51 forks source link

add try from methods #86

Open benmkw opened 4 years ago

benmkw commented 4 years ago

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.

vks commented 3 years ago

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

benmkw commented 3 years ago

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.