Open etiedem opened 1 year ago
Hi @etiedem, coincidentally I just merged #46 which added support for netmasks, but not a parser. The parser does needs a bit of work anyway due to issue #32 but I'm not sure about the value in adding this. In the mean time you could maybe write some code to split these and parse them first into two IpAddrs, then pass them to the new .with_netmask()
constructors?
Thanks for the answer. I did make a little utility function to convert the mask to bitlength and just used the normal parser.
fn netmask_to_bit(netmask: &str) -> u32 {
let bits: u32 = netmask.split(".")
.map(|x| x.parse::<u8>().unwrap().count_ones())
.sum();
bits
}
Allow:
let net: Ipv4Net = "10.0.0.0/255.255.255.252".parse().unwrap();
This would allow additional flexibility since unfortunately not everything represents networks using bit notation.