-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
shift polymorphism to version_parts #21
base: master
Are you sure you want to change the base?
Conversation
After a lot of wandering and some very nice help from people at https://users.rust-lang.org/t/general-version-comparison/33349, I have landed pretty close to where I started. The code is very similar to what you had before I messed with it, but with one important difference: the partial_cmp is now implemented on the enum, which should vastly simplify the necessary comparison code in the loop in Version. Also, the ordering within the enum is used as a primary ordering, and only when enums being compared match are their values compared (so no type mismatch problems, but perhaps new strange behavior if "priority" of parts across a version are not uniformly decreasing.) This is still horribly tedious, and I'm sure there's a better way, but I've floundered a lot with the information present in enums. The enum unifies the type nicely, and it also conveys the ranking of components. I have found it seemingly impossible to retrieve an index value from the enum - using the match to back them out is horrible and definitely error prone, especially since it seems to need repeating for the sake of the ref in the partial_cmp functions. |
PS: I'll squash this all up and also comment it much better soon (please don't merge the PR in the mess that it's in!) If you have tips/ideas for generalizing code and getting rid of those horrible |
5c150c9
to
ed56713
Compare
@timvisee I think this is ready for some more discussion. I've made some changes that differ from your original design, and if you don't like them, that's OK. The highlights are:
I think I'm close to a good start for Conda's purposes. If this PR is something that you see potential in, I can spend some more time on it. Please let me know your thoughts on these changes. On the other hand, if it has gone in weird directions that you'd rather not go, thanks for helping me learn. I'll close this PR and probably move the code into the libronda repo, which will eventually be the python library that uses this stuff: https://github.com/msarahan/libronda |
Follows discussion from #20
I hope this captures what we discussed. It doesn't work yet. I haven't quite gotten it to compile. I was basing a lot on:
https://internals.rust-lang.org/t/simplifying-custom-comparison-and-hashing/5108
which has a demo at https://play.rust-lang.org/?gist=b4445e8d2ffe2e8fe99bce52ecf507d4&version=stable&backtrace=0
The key thing is that each comparison is really 2 comparisons: first a match of priority, which is a proxy for type checking, and the second is a match of the actual value. The priority is what establishes the "trump" behavior that we discussed elsewhere.
PEP440 version comparison is obviously unfinished, and these parts are not connected up to the Version class at all yet. I wanted to get simple tests working in version_part.rs first.