| 1 | //! Network iteration types. |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::{IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#, Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#}; |
| 5 | |
| 6 | use craterust-analyzer cargo maxminddb 0.30.0 crate/::decoderrust-analyzer cargo maxminddb 0.30.0 decoder/; |
| 7 | use craterust-analyzer cargo maxminddb 0.30.0 crate/::errorrust-analyzer cargo maxminddb 0.30.0 error/::MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#; |
| 8 | use craterust-analyzer cargo maxminddb 0.30.0 crate/::readerrust-analyzer cargo maxminddb 0.30.0 reader/::Readerrust-analyzer cargo maxminddb 0.30.0 reader/Reader#; |
| 9 | use craterust-analyzer cargo maxminddb 0.30.0 crate/::resultrust-analyzer cargo maxminddb 0.30.0 result/::{LookupResultrust-analyzer cargo maxminddb 0.30.0 result/LookupResult#, LookupSourcerust-analyzer cargo maxminddb 0.30.0 result/LookupSource#, NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#}; |
| 10 | |
| 11 | /// Options for network iteration. |
| 12 | /// |
| 13 | /// Controls which networks are yielded when iterating over the database |
| 14 | /// with [`Reader::within()`] or [`Reader::networks()`]. |
| 15 | /// |
| 16 | /// # Example |
| 17 | /// |
| 18 | /// ``` |
| 19 | /// use maxminddb::WithinOptions; |
| 20 | /// |
| 21 | /// // Default options (skip aliases, skip networks without data, include empty values) |
| 22 | /// let opts = WithinOptions::default(); |
| 23 | /// |
| 24 | /// // Include aliased networks (IPv4 networks via IPv6 aliases) |
| 25 | /// let opts = WithinOptions::default().include_aliased_networks(); |
| 26 | /// |
| 27 | /// // Skip empty values and include networks without data |
| 28 | /// let opts = WithinOptions::default() |
| 29 | /// .skip_empty_values() |
| 30 | /// .include_networks_without_data(); |
| 31 | /// ``` |
| 32 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 33 | pub struct WithinOptionsrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions# { |
| 34 | /// Include IPv4 networks multiple times when accessed via IPv6 aliases. |
| 35 | include_aliased_networksrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_aliased_networks.: bool, |
| 36 | /// Include networks that have no associated data record. |
| 37 | include_networks_without_datarust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_networks_without_data.: bool, |
| 38 | /// Skip networks whose data is an empty map or empty array. |
| 39 | skip_empty_valuesrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#skip_empty_values.: bool, |
| 40 | } |
| 41 | |
| 42 | impl WithinOptionsrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions# { |
| 43 | /// Include IPv4 networks multiple times when accessed via IPv6 aliases. |
| 44 | /// |
| 45 | /// In IPv6 databases, IPv4 networks are stored at `::0/96`. However, the |
| 46 | /// same data is accessible through several IPv6 prefixes (e.g., |
| 47 | /// `::ffff:0:0/96` for IPv4-mapped IPv6). By default, these aliases are |
| 48 | /// skipped to avoid yielding the same network multiple times. |
| 49 | /// |
| 50 | /// When enabled, the iterator will yield these aliased networks. |
| 51 | #[must_use] |
| 52 | pub fn include_aliased_networksrust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions]include_aliased_networks().(mut self) -> Selfrust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions] { |
| 53 | self.include_aliased_networksrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_aliased_networks. = true; |
| 54 | self |
| 55 | } |
| 56 | |
| 57 | /// Include networks that have no associated data record. |
| 58 | /// |
| 59 | /// Some tree nodes point to "no data" (the node_count sentinel). By default |
| 60 | /// these are skipped. When enabled, these networks are yielded and |
| 61 | /// [`LookupResult::has_data()`] returns `false` for them. |
| 62 | #[must_use] |
| 63 | pub fn include_networks_without_datarust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions]include_networks_without_data().(mut self) -> Selfrust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions] { |
| 64 | self.include_networks_without_datarust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_networks_without_data. = true; |
| 65 | self |
| 66 | } |
| 67 | |
| 68 | /// Skip networks whose data is an empty map or empty array. |
| 69 | /// |
| 70 | /// Some databases store empty maps `{}` or empty arrays `[]` for records |
| 71 | /// without meaningful data. This option filters them out. |
| 72 | #[must_use] |
| 73 | pub fn skip_empty_valuesrust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions]skip_empty_values().(mut self) -> Selfrust-analyzer cargo maxminddb 0.30.0 within/impl#[WithinOptions] { |
| 74 | self.skip_empty_valuesrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#skip_empty_values. = true; |
| 75 | self |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 80 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) struct WithinNoderust-analyzer cargo maxminddb 0.30.0 within/WithinNode# { |
| 81 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node.: usize, |
| 82 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int.: IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#, |
| 83 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len.: usize, |
| 84 | } |
| 85 | |
| 86 | /// Iterator over IP networks within a CIDR range. |
| 87 | /// |
| 88 | /// Created by [`Reader::within()`](crate::Reader::within) or |
| 89 | /// [`Reader::networks()`](crate::Reader::networks). Yields |
| 90 | /// [`LookupResult`] for each network in the database that falls |
| 91 | /// within the specified range. |
| 92 | /// |
| 93 | /// Networks are yielded in depth-first order through the search tree. |
| 94 | /// Use [`LookupResult::decode()`](crate::LookupResult::decode) to |
| 95 | /// deserialize the data for each result. |
| 96 | /// |
| 97 | /// # Example |
| 98 | /// |
| 99 | /// ``` |
| 100 | /// use maxminddb::{Reader, WithinOptions, geoip2}; |
| 101 | /// |
| 102 | /// let reader = Reader::open_readfile("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap(); |
| 103 | /// for result in reader.within("89.160.20.0/24".parse().unwrap(), Default::default()).unwrap() { |
| 104 | /// let lookup = result.unwrap(); |
| 105 | /// if let Some(city) = lookup.decode::<geoip2::City>().unwrap() { |
| 106 | /// println!("{}: {:?}", lookup.network().unwrap(), city.city.names.english); |
| 107 | /// } |
| 108 | /// } |
| 109 | /// ``` |
| 110 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 111 | pub struct Withinrust-analyzer cargo maxminddb 0.30.0 within/Within#<'de, S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>> { |
| 112 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader.: &'de Readerrust-analyzer cargo maxminddb 0.30.0 reader/Reader#<S>, |
| 113 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) node_countrust-analyzer cargo maxminddb 0.30.0 within/Within#node_count.: usize, |
| 114 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) has_ipv4_subtreerust-analyzer cargo maxminddb 0.30.0 within/Within#has_ipv4_subtree.: bool, |
| 115 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) stackrust-analyzer cargo maxminddb 0.30.0 within/Within#stack.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<WithinNoderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#>, |
| 116 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) optionsrust-analyzer cargo maxminddb 0.30.0 within/Within#options.: WithinOptionsrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#, |
| 117 | } |
| 118 | |
| 119 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 120 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) enum IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt# { |
| 121 | V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(u32), |
| 122 | V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(u128), |
| 123 | } |
| 124 | |
| 125 | impl IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt# { |
| 126 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn newrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]new().(ip_addr: IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#) -> Selfrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt] { |
| 127 | match ip_addr { |
| 128 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#(v4) => IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(v4.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 129 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V6#(v6) => IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(v6.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | #[inline(always)] |
| 134 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn get_bitrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]get_bit().(&self, index: usize) -> bool { |
| 135 | match self { |
| 136 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(ip) => (ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u32`][`Shr<usize>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u32`][`Shr<usize>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u32`][`Shr<usize>`]shr().(31 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().index)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1, |
| 137 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(ip) => (ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u128`][`Shr<usize>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u128`][`Shr<usize>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u128`][`Shr<usize>`]shr().(127 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().index)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitAnd<Self>`]bitand().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]eq().1, |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | #[inline(always)] |
| 142 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn set_bitrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]set_bit().(&mut self, index: usize) { |
| 143 | match self { |
| 144 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(ip) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<usize>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<usize>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<usize>`]shl().(31 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().index), |
| 145 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(ip) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`BitOrAssign<Self>`]bitor_assign().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`Shl<usize>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`Shl<usize>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u128][`Shl<usize>`]shl().(127 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().index), |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn bit_countrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]bit_count().(&self) -> usize { |
| 150 | match self { |
| 151 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(_) => 32, |
| 152 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(_) => 128, |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn is_ipv4_in_ipv6rust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]is_ipv4_in_ipv6().(&self) -> bool { |
| 157 | match self { |
| 158 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(_) => false, |
| 159 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(ip) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le().0xFFFFFFFF, |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | impl<'de, S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Withinrust-analyzer cargo maxminddb 0.30.0 within/Within#<'de, S> { |
| 165 | type Itemrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`][Iterator]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<LookupResultrust-analyzer cargo maxminddb 0.30.0 result/LookupResult#<'de, S>, MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#>; |
| 166 | |
| 167 | fn nextrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 168 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current) = self.stackrust-analyzer cargo maxminddb 0.30.0 within/Within#stack..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 169 | let bit_count = current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int..bit_countrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]bit_count().(); |
| 170 | |
| 171 | // Skip networks that are aliases for the IPv4 network (unless option is set) |
| 172 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.optionsrust-analyzer cargo maxminddb 0.30.0 within/Within#options..include_aliased_networksrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_aliased_networks. |
| 173 | && self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..ipv4_startrust-analyzer cargo maxminddb 0.30.0 reader/Reader#ipv4_start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 |
| 174 | && current.noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..ipv4_startrust-analyzer cargo maxminddb 0.30.0 reader/Reader#ipv4_start. |
| 175 | && bit_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().128 |
| 176 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int..is_ipv4_in_ipv6rust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]is_ipv4_in_ipv6().() |
| 177 | { |
| 178 | continue; |
| 179 | } |
| 180 | |
| 181 | match current.noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][Ord]cmp().(&self.node_countrust-analyzer cargo maxminddb 0.30.0 within/Within#node_count.) { |
| 182 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => { |
| 183 | // This is a data node, emit it and we're done (until the following next call) |
| 184 | // Resolve the pointer to a data offset |
| 185 | let data_offset = match self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..resolve_data_pointerrust-analyzer cargo maxminddb 0.30.0 reader/impl#[`Reader<S>`]resolve_data_pointer().(current.noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node.) { |
| 186 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset) => offset, |
| 187 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)), |
| 188 | }; |
| 189 | |
| 190 | // Check if we should skip empty values |
| 191 | if self.optionsrust-analyzer cargo maxminddb 0.30.0 within/Within#options..skip_empty_valuesrust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#skip_empty_values. { |
| 192 | match self.is_empty_value_atrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]is_empty_value_at().(data_offset) { |
| 193 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true) => continue, // Skip empty value |
| 194 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false) => {} // Not empty, proceed |
| 195 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)), |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | let network_kind = self.network_kindrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]network_kind().(¤t); |
| 200 | let ip_addr = network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr().(network_kind, current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int.); |
| 201 | |
| 202 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LookupResultrust-analyzer cargo maxminddb 0.30.0 result/LookupResult#::new_foundrust-analyzer cargo maxminddb 0.30.0 result/impl#[`LookupResult<'a, S>`]new_found().( |
| 203 | self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader., |
| 204 | data_offset, |
| 205 | current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. as u8, |
| 206 | ip_addr, |
| 207 | LookupSourcerust-analyzer cargo maxminddb 0.30.0 result/LookupSource#::Iterrust-analyzer cargo maxminddb 0.30.0 result/LookupSource#Iter#, |
| 208 | network_kind, |
| 209 | ))); |
| 210 | } |
| 211 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => { |
| 212 | // Dead end (no data) - include if option is set |
| 213 | if self.optionsrust-analyzer cargo maxminddb 0.30.0 within/Within#options..include_networks_without_datarust-analyzer cargo maxminddb 0.30.0 within/WithinOptions#include_networks_without_data. { |
| 214 | let network_kind = self.network_kindrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]network_kind().(¤t); |
| 215 | let ip_addr = network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr().(network_kind, current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int.); |
| 216 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LookupResultrust-analyzer cargo maxminddb 0.30.0 result/LookupResult#::new_not_foundrust-analyzer cargo maxminddb 0.30.0 result/impl#[`LookupResult<'a, S>`]new_not_found().( |
| 217 | self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader., |
| 218 | current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. as u8, |
| 219 | ip_addr, |
| 220 | LookupSourcerust-analyzer cargo maxminddb 0.30.0 result/LookupSource#::Iterrust-analyzer cargo maxminddb 0.30.0 result/LookupSource#Iter#, |
| 221 | network_kind, |
| 222 | ))); |
| 223 | } |
| 224 | // Otherwise skip (current behavior) |
| 225 | } |
| 226 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => { |
| 227 | if current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().bit_count { |
| 228 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#::invalid_databaserust-analyzer cargo maxminddb 0.30.0 error/impl#[MaxMindDbError]invalid_database().( |
| 229 | "search tree appears to have a cycle or invalid structure (traversal exceeded the address bit length)", |
| 230 | ))); |
| 231 | } |
| 232 | // In order traversal of our children |
| 233 | // right/1-bit |
| 234 | let mut right_ip_int = current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int.; |
| 235 | |
| 236 | if current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bit_count { |
| 237 | right_ip_int.set_bitrust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]set_bit().(current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len.); |
| 238 | } |
| 239 | |
| 240 | self.push_childrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]push_child().(current.noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node., 1, right_ip_int, current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 241 | // left/0-bit |
| 242 | self.push_childrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]push_child().(current.noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node., 0, current.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int., current.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | impl<'de, S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>> Withinrust-analyzer cargo maxminddb 0.30.0 within/Within#<'de, S> { |
| 251 | #[inline(always)] |
| 252 | fn network_kindrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]network_kind().(&self, node: &WithinNoderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#) -> NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind# { |
| 253 | match node.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int. { |
| 254 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(_) if self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..metadatarust-analyzer cargo maxminddb 0.30.0 reader/impl#[`Reader<S>`]metadata().().ip_versionrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#ip_version. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().6 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.has_ipv4_subtreerust-analyzer cargo maxminddb 0.30.0 within/Within#has_ipv4_subtree. => { |
| 255 | NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V6rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V6# |
| 256 | } |
| 257 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(_) => NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V4rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V4#, |
| 258 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(_) |
| 259 | if node.ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int..is_ipv4_in_ipv6rust-analyzer cargo maxminddb 0.30.0 within/impl#[IpInt]is_ipv4_in_ipv6().() |
| 260 | && self.has_ipv4_subtreerust-analyzer cargo maxminddb 0.30.0 within/Within#has_ipv4_subtree. |
| 261 | && node.prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..ipv4_start_bit_depthrust-analyzer cargo maxminddb 0.30.0 reader/Reader#ipv4_start_bit_depth. => |
| 262 | { |
| 263 | NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V4InV6Subtreerust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V4InV6Subtree# |
| 264 | } |
| 265 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(_) => NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V6rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V6#, |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | fn push_childrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]push_child().( |
| 270 | &mut self, |
| 271 | parent_node: usize, |
| 272 | direction: usize, |
| 273 | ip_int: IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#, |
| 274 | prefix_len: usize, |
| 275 | ) { |
| 276 | let node = self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..read_noderust-analyzer cargo maxminddb 0.30.0 reader/impl#[`Reader<S>`]read_node().(parent_node, direction); |
| 277 | self.stackrust-analyzer cargo maxminddb 0.30.0 within/Within#stack..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(WithinNoderust-analyzer cargo maxminddb 0.30.0 within/WithinNode# { |
| 278 | noderust-analyzer cargo maxminddb 0.30.0 within/WithinNode#node., |
| 279 | ip_intrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#ip_int., |
| 280 | prefix_lenrust-analyzer cargo maxminddb 0.30.0 within/WithinNode#prefix_len., |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | /// Check if the value at the given data offset is an empty map or array. |
| 285 | fn is_empty_value_atrust-analyzer cargo maxminddb 0.30.0 within/impl#[`Within<'de, S>`]is_empty_value_at().(&self, data_offset: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#> { |
| 286 | let buf = &self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..bufrust-analyzer cargo maxminddb 0.30.0 reader/Reader#buf..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..pointer_baserust-analyzer cargo maxminddb 0.30.0 reader/Reader#pointer_base...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 287 | let mut dec = |
| 288 | decoderrust-analyzer cargo maxminddb 0.30.0 decoder/::Decoderrust-analyzer cargo maxminddb 0.30.0 decoder/Decoder#::new_with_limitrust-analyzer cargo maxminddb 0.30.0 decoder/impl#[`Decoder<'de>`]new_with_limit().(buf, data_offset, self.readerrust-analyzer cargo maxminddb 0.30.0 within/Within#reader..data_section_lenrust-analyzer cargo maxminddb 0.30.0 reader/Reader#data_section_len.); |
| 289 | let (size, type_num) = dec.peek_typerust-analyzer cargo maxminddb 0.30.0 decoder/impl#[`Decoder<'de>`]peek_type().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 290 | match type_num { |
| 291 | decoderrust-analyzer cargo maxminddb 0.30.0 decoder/::TYPE_MAPrust-analyzer cargo maxminddb 0.30.0 decoder/TYPE_MAP. | decoderrust-analyzer cargo maxminddb 0.30.0 decoder/::TYPE_ARRAYrust-analyzer cargo maxminddb 0.30.0 decoder/TYPE_ARRAY. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0), |
| 292 | _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false), // Non-container types are never "empty" |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | #[inline(always)] |
| 298 | fn network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr().(network_kind: NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#, ip_int: IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#) -> IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr# { |
| 299 | let ip_addr = ip_int_to_addrrust-analyzer cargo maxminddb 0.30.0 within/ip_int_to_addr().(&ip_int); |
| 300 | match (network_kind, ip_int, ip_addr) { |
| 301 | // Low IPv6 tree keys are normally formatted as IPv4 addresses for IPv4 |
| 302 | // subtree records. When the record is really IPv6, preserve the low |
| 303 | // IPv6 bits instead of collapsing the network to ::. |
| 304 | (NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V6rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V6#, IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(ip), IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#(_)) => IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V6#(ip.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 305 | // Defensive fallback for IPv4 CIDR iteration in IPv6 databases without |
| 306 | // an IPv4 subtree. Reader::within() should seed those as IpInt::V6(0). |
| 307 | (NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V6rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V6#, IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(_), IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#(_)) => IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V6#(Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#::UNSPECIFIEDrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/impl#[Ipv6Addr]UNSPECIFIED.), |
| 308 | (_, _, ip_addr) => ip_addr, |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /// Convert IpInt to IpAddr |
| 313 | #[inline(always)] |
| 314 | pub(craterust-analyzer cargo maxminddb 0.30.0 crate/) fn ip_int_to_addrrust-analyzer cargo maxminddb 0.30.0 within/ip_int_to_addr().(ip_int: &IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#) -> IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr# { |
| 315 | match ip_int { |
| 316 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V4rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V4#(ip) => IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ip).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 317 | IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(ip) => { |
| 318 | // Check if this is an IPv4-mapped IPv6 address. |
| 319 | if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ip rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]le().0xFFFFFFFF { |
| 320 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ip as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 321 | } else { |
| 322 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V6#((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ip).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | #[cfg(test)] |
| 329 | mod testsrust-analyzer cargo maxminddb 0.30.0 within/tests/ { |
| 330 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::{IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#, Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#, Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#}; |
| 331 | |
| 332 | use craterust-analyzer cargo maxminddb 0.30.0 crate/::resultrust-analyzer cargo maxminddb 0.30.0 result/::NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#; |
| 333 | |
| 334 | use superrust-analyzer cargo maxminddb 0.30.0 within/::{network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr()., IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#}; |
| 335 | |
| 336 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 337 | fn network_ip_addr_preserves_low_ipv6_bitsrust-analyzer cargo maxminddb 0.30.0 within/tests/network_ip_addr_preserves_low_ipv6_bits().() { |
| 338 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 339 | network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr().(NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V6rust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V6#, IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(1)), |
| 340 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V6#(Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/impl#[Ipv6Addr][`From<u128>`]from().(1_u128)) |
| 341 | ); |
| 342 | } |
| 343 | |
| 344 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 345 | fn network_ip_addr_formats_ipv4_subtree_records_as_ipv4rust-analyzer cargo maxminddb 0.30.0 within/tests/network_ip_addr_formats_ipv4_subtree_records_as_ipv4().() { |
| 346 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 347 | network_ip_addrrust-analyzer cargo maxminddb 0.30.0 within/network_ip_addr().(NetworkKindrust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#::V4InV6Subtreerust-analyzer cargo maxminddb 0.30.0 result/NetworkKind#V4InV6Subtree#, IpIntrust-analyzer cargo maxminddb 0.30.0 within/IpInt#::V6rust-analyzer cargo maxminddb 0.30.0 within/IpInt#V6#(1)), |
| 348 | IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#::V4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#V4#(Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/impl#[Ipv4Addr][`From<u32>`]from().(1_u32)) |
| 349 | ); |
| 350 | } |
| 351 | } |