I want to be able to use this as a key in a HashMap. I know exactly how I want the ordering to behave. But I'm not quite sure how to implement it. When I build the code it complains that std::cmp::Eq isn't implemented for ArgSpec. This is expected, but my question is how to implement it. I tried the following (in the same module):
This builds, but I'm going to admit I find it a little confusing that it does (since ArgSpec contains members which are Option<>). But looking beyond this snippet, ArgSpec will eventually contain other members which shouldn't be used to key the data (only opt and lopt should do that). Am I correct in assuming this means I have to manually implement the traits?
For comparisons, None is less than Some, and the rest should be straightforward.
But yes, if you want a partial comparison, you will need to implement the traits manually. When you do, take care that they are all consistent, per the notes on PartialEq and Hash:
One way you could "cheat" is to group your comparison items into one sub-struct and derive on that. Then the manual impls on the full struct can just forward to that one member. Someday there may be a way to derive "delegate" impls like this.