Skip to content

feat: construct networks from an address and a prefix length - #106

Merged
3Hren merged 1 commit into
mainfrom
feat/tryfrom-addr-prefix
Aug 11, 2026
Merged

feat: construct networks from an address and a prefix length#106
3Hren merged 1 commit into
mainfrom
feat/tryfrom-addr-prefix

Conversation

@3Hren

@3Hren 3Hren commented Aug 11, 2026

Copy link
Copy Markdown
Member

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.

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.
@3Hren
3Hren merged commit 0d88e73 into main Aug 11, 2026
6 checks passed
@3Hren
3Hren deleted the feat/tryfrom-addr-prefix branch August 11, 2026 09:56
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.

1 participant