feat: construct networks from an address and a prefix length - #106
Merged
Conversation
The contiguous wrapper could only be built by parsing a string, so callers holding an address and a prefix length had to format and reparse to reach it, even though a mask derived from a prefix length is contiguous by construction. The enum network also lacked a conversion taking a family-agnostic address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The contiguous wrapper could only be built by parsing a string. A caller already holding an address and a prefix length had to format the pair and reparse it to reach the wrapper, even though a mask derived from a prefix length is contiguous by construction and needs no check. The enum network also had conversions for each concrete address type but none for the family-agnostic one.
This adds the four conversions that close both gaps, for both address families. Each delegates to an existing typed constructor rather than rederiving the mask, so normalization and the prefix-length bound keep their single source, and the overflow error is the one those constructors already return.
The wrapper conversions carry an example apiece, covering the success and the overflow path, and state why skipping the contiguity check is sound. Property tests assert the resulting prefix length, the contiguity of the mask through the inner check rather than the constant-true override, and the exact boundary between accepted and rejected prefix lengths. Unit tests pin the boundary deterministically for both families.