Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with num-traits 0.2.*. #10

Closed
olson-sean-k opened this issue Feb 17, 2018 · 3 comments
Closed

Integrate with num-traits 0.2.*. #10

olson-sean-k opened this issue Feb 17, 2018 · 3 comments
Milestone

Comments

@olson-sean-k
Copy link
Owner

olson-sean-k commented Feb 17, 2018

The 0.2.* series of the num-traits crate includes a Real trait (introduced in 0.1.42) that is nearly identical to Decorum's. Before hitting 0.1.0, Decorum should integrate with these changes and replace it's Real trait with num-traits'.

This will be tricky though. num-traits currently provides a blanket implementation such that T: Float ⇒ T: Real (i.e., impl<T> Real for T where T: Float { ... }). This makes it impossible to write implementations of the Float and Real traits for ConstrainedFloat that are parameterized over the input FloatConstraint type. I'm still not sure how to work around this.

@olson-sean-k
Copy link
Owner Author

olson-sean-k commented Mar 6, 2018

One straightforward solution is to implement Real directly against the non-parameterized types re-exported by Decorum (NotNan and Finite). Unfortunately, this would mean that Real would not be implicitly implemented based on the FloatConstraint used to construct the type. If a new proxy type were added, it would be easy to forget the corresponding Real implementation, for example.

This would also involve a lot of duplicated code. A macro could help with this, but it's a bit ugly. Since there is no way to address this without a breaking change to num-traits, it will probably be necessary to do something like this.

I've opened a related issue against num-traits.

@olson-sean-k
Copy link
Owner Author

7d9449a upgrades num-traits to 0.2.* and implements the Real trait from that crate for relevant proxy types via a macro.

There are some small differences between Decorum's Real and num-traits' Real, so that commit does not remove the trait from Decorum. Instead, it simply implements both. That isn't ideal; at the very least, it may be worth advocating for using one over the other in documentation.

@olson-sean-k
Copy link
Owner Author

This issue is primarily about upgrading to num-traits 0.2.*, so I'll close it. It'll probably be worth considering how to move forward with the Real traits though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant