-
Notifications
You must be signed in to change notification settings - Fork 40
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
Inconvenient NetworkSize #102
Comments
Hi @vorner thanks for bringing this up. It seemed natural that IPv4 size should be 32 bits and IPv6 should be u128. Given that, the only way to have an API around both the types was to have a generic |
Implementing bunch of traits would help somewhat. Nevertheless, I still believe it would be less convenient that it would have to be and would be a lot of work and more code. I do agree that size of IPv4 network range should be So, my proposals are (in order of how I personally like them):
|
I see your point. I am a bit hesitant to change the external API since this has been out there for a while now. A quick Github search did not show any usage of |
I think this should have been closed via #175. |
I have a new idea for this type that I find would solve the problem elegantly. // status quo
pub enum NetworkSize {
V4(u32),
V6(u128),
} In this crate it's impossible (without unsafe) to create an Rust has a great way of representing non-zero integers like this https://doc.rust-lang.org/stable/core/num/struct.NonZero.html. If we're too keep the existing structure, but would like to improve the status quo on #130 #178, I'd recommend returning Due to niche optimizations by the rust compiler // proposal 1
pub enum NetworkSize {
V4(NonZeroU32),
V6(NonZeroU128),
MAX_V6,
} In addition to this change I would also make the implementation of
None of these really require users know the inner workings of It may be true that there are better implementations no-one has considered yet, and we can open the door to this change again in the future without breaking existing code.
I would love to help resolve the long-term stabilization issue in this project, I'm happy to write up a Draft PR showing what the a stabilized API here could look like. |
Hello
I wonder what the motivation behind the
NetworkSize
is. As I understand, the purpose of theIpNetwork
enum is to generalize handling of both IPv4 and IPv6 networks. If it is so, why doesn'tIpNetwork::size
simply returnu128
? TheNetworkSize
isn't smaller, doesn't have many traits (eg. can't be summed together, doesn't have aDisplay
implementation, doesn't support comparing to literals well…Anyway, thank you for working on this, it is something I've stumbled upon multiple times that I'd like to have.
The text was updated successfully, but these errors were encountered: