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

Add TryFrom<u8> Implementation for ZoomLevel #9

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

hiratara
Copy link
Contributor

@hiratara hiratara commented Jan 3, 2025

Hello,

In my project, I’m using u8 values to represent zoom levels for a slippy map, as this makes it straightforward to increment ( zoom += 1 ), decrement, or specify zoom levels directly using raw integers, such as from command-line arguments ( myapp --zoom=12 ).

However, I noticed that ZoomLevel currently lacks a way to be constructed directly from a raw u8 value. To address this, I’ve implemented the TryFrom<u8> trait for ZoomLevel, allowing for conversions like:

let zoom: ZoomLevel = 12u8.try_into()?;

Additionally, I’ve introduced a new macro, generate_zoom_level, to simplify the boilerplate code involved in defining the ZoomLevel enum. This macro makes it easier to manage and extend the enum when dealing with large ranges of zoom levels.

I hope you find this contribution useful, and I look forward to your feedback.

Copy link
Owner

@edouardpoitras edouardpoitras left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@edouardpoitras edouardpoitras merged commit 1362c1c into edouardpoitras:main Jan 3, 2025
3 checks passed
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.

2 participants