-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add some forwarding impls Hash, Ord, PartialOrd #37
Conversation
I think the current sort order for unit enums isn't intuitive, or maybe incorrectly implemented. See how the The reason we're getting this is because the comparison is performed over the storage impl #[derive(PartialEq, PartialOrd)]
enum Foo {
First,
Second,
}
fn main() {
assert!(Foo::First < Foo::Second);
assert!([Some(Foo::First), None] > [None, Some(Foo::Second)]);
} |
I'm very much considering whether or not to revert d85726c. It achieves the intuitive sort ordering, but through a much slower implementation. The same result could be achieved by using a custom #[derive(PartialEq, PartialOrd)]
enum Option<T> {
Some(T),
None,
}
#[derive(PartialEq, PartialOrd)]
enum Foo {
First,
Second,
}
fn main() {
assert!(Foo::First < Foo::Second);
assert!([Option::Some(Foo::First), Option::None] < [Option::None, Option::Some(Foo::Second)]);
} The only difference between |
e943998
to
80fbf60
Compare
I don't think you need the forwarding for |
names.push(name.clone()); | ||
entry.push(quote!(option_to_entry(#name, key))); | ||
variants.push(&variant.ident); | ||
names.push(format_ident!("_{}", index)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename variants
and names
to just variant
and name
?
Personally, I prefer #ident::#variant
to #ident::#variants
.
I feel like plurals should be reserved for cases where it's meant to be expanded directly into a list, like #(#field_inits,)*
.
I think a better name than #ident
would be great too. Maybe #target
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I don't have particularly strongly held opinions here. The larger improvements is reducing the number of vectors in use and moving the code closer to how it's used which makes it easier to work with.
One thought I have though is that pluralized names is useful to identify what's being looped over in the quote!
macro call even though it looks a little awkward.
Interesting! I suppose it does make sense that the codegen bloat to accomplish the same computational complexity isn't a worthwhile tradeoff (for when we generate an |
I've omitted support for any variants in this PR, since they are a lot of work. But I've marked the relevant test cases with a
TODO
for now and we'll make sure that they're added before the next release (I only need unit enums right now for my downstream project).I've also modified more existing trait impls to impl and forward to their underlying implementations. This is important to improve the chances that default trait functions also can be optimized, such as
PartialEq::ne
, ora != b
.The latter ought to be done for as much as possible.