krisprice / ipnet

IpNet, Ipv4Net, and Ipv6Net types and methods for Rust
Apache License 2.0
122 stars 26 forks source link

Enhancement: Trait for afi-independent methods #38

Closed benmaddison closed 2 years ago

benmaddison commented 2 years ago

I frequently find myself writing code that should be generic over IP address families, but I'm prevented by the lack of a way to express the bound "has a prefix_len(&self) -> u8 method", for example.

It should be straight-forward (I say without actually having read the code :-)) to create a trait that provides the functions which currently exist on Ipv4Net and Ipv6Net, and which have a shared signature, and move the existing implementations of those to trait implementations.

@krisprice please let me know if you're open to the principal, and I'll take a stab at a PR.

krisprice commented 2 years ago

Hi @benmaddison , I'm not quite following what it is you're doing and so not sure if this library is the right place for it, can you elaborate a bit more / give an example?

krisprice commented 2 years ago

@benmaddison don't know if you ever did go ahead and experiment with this, gonna go ahead and close it but raise it again if you like.