ipnetwork icon indicating copy to clipboard operation
ipnetwork copied to clipboard

Implement subtraction between `IpNetwork`s

Open jvff opened this issue 5 years ago • 1 comments

This PR implements the Sub trait for IpNetwork, Ipv4Network and Ipv6Network. There are two possibilities: either a single IP network item is subtracted from the original IP network, or multiple IP network items are subtracted from the original IP network.

The result of the subtraction operation is always an iterator, which can contain zero or more IP network items. For subtracting a single item, the iterator has a rather simple representation in memory and does implement Copy. When subtracting multiple items, a linked list of Box<dyn Iterator> is returned, so the resulting type has a more complex representation.

With this PR it is still not currently possible to subtract between IP networks with different protocols (for example, subtract an IPv4 network from an IPv6 network or vice-versa). Attempting to do so will lead the code to panic.

jvff avatar Feb 15 '20 17:02 jvff

this pr is cool

ctrlcctrlv avatar Jun 13 '23 18:06 ctrlcctrlv