Should `prefix_len` be it's own type?
krisprice opened this issue · comments
Should prefix_len
be it's own type? This seems like newtype overload, but the API guidelines would tend to indicate it should be.
Currently the new()
constructors clamp the prefix_len
to between 0 and 32 or 0 and 128 for IPv4 and IPv6 respectively. This is instead of returning a Result
with a error if prefix_len
is not in valid bounds. Is returning a Result
the better thing to do? This is a very simple library, and the outcome for a prefix_len
greater than the bounds is the same as supplying a prefix_len
of the maximum bound anyway.
Implementing a new type would mean implementing new types for both IPv4 and IPv6 prefix lengths. A new type for their errors. And, a constructor for each. It's not clear this is any better than changing the constructor on the Ipv4Net
and Ipv6Net
implementations to return an error as described above. It would seem better to take that option if anything.