Nearing 1.0 release, feedback and code reviews are very welcome. Open an issue or comment here on the Reddit post.
This module provides types and methods for working with IPv4 and IPv6 network addresses, commonly called IP prefixes. It only uses stable Rust features so it compiles using the stable toolchain. And its design aligns to the existing IpAddr
, Ipv4Addr
, and Ipv6Addr
types provided in the Rust standard library.
The module includes extension traits to provide Add, Sub, BitAnd, and BitOr operations to Ipv4Addr
and Ipv6Addr
.
Available on [Crates.io] and read the [documentation] for the full details.
IpNet::new()
truncate the input IpAddr
to the prefix_len and store that instead? Users may expect one behavior over the other. Truncating it at creation time means that the provided address can't be returned if the user has a need for it, and sort behaviour won't be influenced by it. Though we don't have a way to access it as the field is not public there is no address()
method, this could be added. There is a trunc()
method that does truncate the network, but chaining IpNet::new().trunc()
or IpNet::from().unwrap().trunc()
is kind of ugly. I am leaning towards changing this behaviour so the address is truncated at creation, then in future if Rust provides default args having a default truncate=true
argument that users can override if they don't want it truncated.new_with_trunc()
constructor method. Or perhaps a series of builder methods?subnets()
and hosts()
should return an iterator type Subnets
and Hosts
respectively rather than the generic IpNetIter<T>
they currently return. See here.Copyright (c) 2017, Juniper Networks, Inc. All rights reserved.
This code is licensed to you under the Apache License, Version 2.0 (the "License"). You may not use this code except in compliance with the License. This code is not an official Juniper product. You can obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0