diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-01-23 20:15:26 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-02-06 12:05:57 +0000 |
| commit | b51b2220449774eb99ab9bf7648246fb427324bd (patch) | |
| tree | d6b2e40e9c783f873c7934443c38c7a6affef185 | |
| parent | a5e13d5272cf03903ec2809a5268868000d64f06 (diff) | |
| download | mullvadvpn-b51b2220449774eb99ab9bf7648246fb427324bd.tar.xz mullvadvpn-b51b2220449774eb99ab9bf7648246fb427324bd.zip | |
Create `IpNetworkSub` trait
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/android/ipnetwork_sub.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/talpid-core/src/tunnel/tun_provider/android/ipnetwork_sub.rs b/talpid-core/src/tunnel/tun_provider/android/ipnetwork_sub.rs index 2beee29f3c..d2fa1afbad 100644 --- a/talpid-core/src/tunnel/tun_provider/android/ipnetwork_sub.rs +++ b/talpid-core/src/tunnel/tun_provider/android/ipnetwork_sub.rs @@ -1,6 +1,7 @@ use ipnetwork::{Ipv4Network, Ipv6Network}; use std::{ fmt::Debug, + iter, marker::PhantomData, ops::{Add, BitAnd, BitXor, Not, Shl, Sub}, }; @@ -136,3 +137,19 @@ where } } } + +pub trait IpNetworkSub: Copy + Sized + 'static { + type Output: Iterator<Item = Self>; + + fn sub(self, other: Self) -> Self::Output; + + fn sub_all(self, others: impl IntoIterator<Item = Self>) -> Box<dyn Iterator<Item = Self>> { + let mut result: Box<dyn Iterator<Item = Self>> = Box::new(iter::once(self)); + + for other in others { + result = Box::new(result.flat_map(move |network| network.sub(other))); + } + + result + } +} |
