-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
improve newtype_index!
macro
#50337
Comments
I can tackle this! |
FWIW I'd prefer we do |
Oh, that thing stopping "Go To Definition" from working 😄 |
|
Oh neat, I was not aware of #45388 |
…Simulacrum use `NonZeroU32` in `newtype_index!`macro, change syntax Various improvements to the `newtype_index!` macro: - Use `NonZeroU32` so that `Option<T>` is cheap - More ergonomic helper method, no need to import `Idx` trait all the time - Improve syntax to use `struct` keyword so that ripgrep works to find type def'n Fixes rust-lang#50337 I'm curious to see if this passes tests =)
We have this handy macro
newtype_index!
that creates a, well, newtype'd index:However, I think it could be improved in four ways:
First, the syntax should change to include the keyword
struct
andpub
. This would help with people trying to find the definition of the type. I'd probably switch to{}
form at the same time, but that's not necessary:Second, doing this would also allow us to support arbitrary visibilities. For example, I'd like to make
crate struct RegionAtLocationIndex
:Third, we should change to incorporate
NonZero
. That is, the original example would currently expands to something like:but I want it to expand to:
Of course,
0
is a valid index, so the various initialization and accessor routines would have to add or subtract one as appropriate.Using
NonZero
would mean thatOption<T>
would be represented still as a single u32.Finally, fourth, as a convenience, it would be nice to define inherent (non-trait) methods, so that using these types did not require importing the
Idx
trait:cc @Nashenas88 @spastorino @sgrif
The text was updated successfully, but these errors were encountered: