Skip to content
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

Generate an enum with one variant for each unit, use that for iteration. #215

Merged
merged 3 commits into from Nov 7, 2020

Conversation

bheisler
Copy link
Contributor

This extends the quantity! macro to generate a non-exhaustive enum with one variant per unit. A static slice of the different potential values of this enum is also generated, which is exposed publicly through a units() function, which returns an iterator. This can be used to iterate over the different units.

@adamreichold
Copy link
Contributor

This indeed much simpler than doing tricks with HList! I think a test case that exercises the API would be nice.

Copy link
Owner

@iliekturtles iliekturtles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

src/quantity.rs Outdated Show resolved Hide resolved
src/quantity.rs Outdated Show resolved Hide resolved
src/quantity.rs Outdated Show resolved Hide resolved
src/quantity.rs Outdated Show resolved Hide resolved
src/quantity.rs Outdated Show resolved Hide resolved
@bheisler
Copy link
Contributor Author

I think I've fixed everything.

Copy link
Owner

@iliekturtles iliekturtles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more minor changes. I think the code looks good so far but I have only reviewed through github. I want to do one more review, hopefully this weekend, with the compiler then I think we'll be able to merge.

src/quantity.rs Outdated Show resolved Hide resolved
src/si/volume.rs Outdated Show resolved Hide resolved
- Remove inline on units()
- Move and rename unit test.
@iliekturtles
Copy link
Owner

I haven't forgotten about this, I just didn't finish my review this weekend. I like using $plural for the doc comment and think it would be good to switch struct $unit to use the same value if there is no user-provided comment and use the user-provided comment on the enum.

@iliekturtles iliekturtles merged commit a77ef61 into iliekturtles:master Nov 7, 2020
@iliekturtles
Copy link
Owner

Merged! Thanks so much for the PR and sorry for the delays. My quest to use the user-provided documentation on the enum members ended up being a dead-end because you can't use a macro in place of an enum member. I will submit a separate PR to convert struct $unit to use $plural.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants