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 ip_mask_to_prefix_checked #214

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Jan 9, 2025

This PR adds some new public APIs: ip_mask_to_prefix_checked, ipv4_mask_to_prefix_checked and ipv6_mask_to_prefix_checked.

Like in #203, the rationale for adding new functions that return an Option instead is so that user's may unwrap the result to trigger a compile-time error if anything is wrong.

An ugly wart of const is that the for construct is not yet available, which means that I had to fall back to using a while loop + loop variable for iteration in ipv6_mask_to_prefix_checked.

I understand if this change is a bit too much, as the const-ification now starts to enforce a coding style which feels a bit unidiomatic. Please, think this one through a bit and do come with feedback!

Edit: These APIs will allow us to add a const ditto of IpNetwork::with_netmask if we wish to do that, which is kind of nice 😊

@achanda achanda merged commit 0deb2ab into achanda:master Jan 13, 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