-
Notifications
You must be signed in to change notification settings - Fork 60
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 FromStr impl for operands #171
Conversation
autogen/header.rs
Outdated
let number = e.value; | ||
seen_discriminator.insert(e.value, name.clone()); | ||
enumerants.push(quote! { #name = #number }); | ||
from_prim_list.push(quote! { #number => #kind::#name }); | ||
from_str_impl.push(quote! { #name_str => Ok(#kind::#name), }); |
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.
Could this be
from_str_impl.push(quote! { #name_str => Ok(#kind::#name), }); | |
from_str_impl.push(quote! { #name_str => Ok(Self::#name), }); |
To save quite a bunch of characters on every line? That fits with the Result<Self, ...>
return type as well.
EDIT: I guess the same cleanup applies to from_prim_list
?
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.
Awesome! Approval from me, if counts at all 😅
It's sad there's no #[derive(FromStr)]
though, these are about ~800 extra lines for strings that appear identical to their enum
variant yet could be generated at compile-time instead of checked in. The perks of auto-generated files 😁
let number = e.value; | ||
seen_discriminator.insert(e.value, name.clone()); | ||
enumerants.push(quote! { #name = #number }); | ||
from_prim_list.push(quote! { #number => #kind::#name }); | ||
from_prim_list.push(quote! { #number => Self::#name }); | ||
from_str_impl.push(quote! { #name_str => Ok(Self::#name), }); |
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 think the aliases should probably also appear. Right now ClosestHitKHR
isn't recognised but ClosestHitNV
is for example, however the new way forward it through the KHR extension.
This would be a pain to implement all the boilerplate for outside of rspirv, so throwing it in here for our use case in rust-gpu.
Note that this does not implement FromStr for
bitflags!
operands, but implementing FromStr for those becomes a bit opinionated - do you create a list of values? how do you separate each individual value? so it's not really possible to impl it in an unopinionated way (and besides, there's not many bitflags, it's easy enough for users to implement their own FromStr).