Debian Codegraph @

UPGRADING.md

raw symbols SCIP
1 # Upgrading Guide
2
3 ## 0.28 to 0.29
4
5 ### Reader Metadata
6
7 `Reader::metadata` is now private. Use `Reader::metadata()` to access
8 validated metadata by shared reference.
9
10 **Before (0.28):**
11
12 ```rust
13 let database_type = &reader.metadata.database_type;
14 ```
15
16 **After (0.29):**
17
18 ```rust
19 let database_type = &reader.metadata().database_type;
20 ```
21
22 ### Metadata Build Time
23
24 `Metadata::build_time()` now returns `Result<SystemTime, MaxMindDbError>`.
25 Databases whose `build_epoch` cannot be represented as `SystemTime` are
26 rejected as invalid when opened or verified.
27
28 **Before (0.28):**
29
30 ```rust
31 let build_time = reader.metadata.build_time();
32 ```
33
34 **After (0.29):**
35
36 ```rust
37 let build_time = reader.metadata().build_time()?;
38 ```
39
40 ### Metadata Validation
41
42 Opening a database now rejects unsupported major format versions, unsupported
43 IP versions, zero-node search trees, and unrepresentable build epochs as
44 invalid databases. Minor format versions are still accepted for forward
45 compatibility.
46
47 ## 0.26 to 0.27
48
49 This release includes significant API changes to improve ergonomics and enable
50 new features like lazy decoding and selective field access.
51
52 ### Lookup API
53
54 The `lookup()` method now returns a `LookupResult` that supports lazy decoding.
55
56 **Before (0.26):**
57
58 ```rust
59 let city: Option<geoip2::City> = reader.lookup(ip)?;
60 if let Some(city) = city {
61 println!("{:?}", city.city);
62 }
63 ```
64
65 **After (0.27):**
66
67 ```rust
68 let result = reader.lookup(ip)?;
69 if let Some(city) = result.decode::<geoip2::City>()? {
70 println!("{:?}", city.city);
71 }
72 ```
73
74 The new API allows you to:
75
76 - Check if data exists without decoding: `result.has_data()`
77 - Get the network for the IP: `result.network()?`
78 - Decode only specific fields: `result.decode_path(&[...])?`
79
80 ### lookup_prefix Removal
81
82 The `lookup_prefix()` method has been removed. Use `lookup()` with `network()`.
83
84 **Before (0.26):**
85
86 ```rust
87 let (city, prefix_len) = reader.lookup_prefix(ip)?;
88 ```
89
90 **After (0.27):**
91
92 ```rust
93 let result = reader.lookup(ip)?;
94 let city = result.decode::<geoip2::City>()?;
95 let network = result.network()?; // Returns IpNetwork with prefix
96 ```
97
98 ### Within Iterator
99
100 The `within()` method now requires a `WithinOptions` parameter.
101
102 **Before (0.26):**
103
104 ```rust
105 for item in reader.within::<geoip2::City>(cidr)? {
106 let item = item?;
107 println!("{}: {:?}", item.ip_net, item.info);
108 }
109 ```
110
111 **After (0.27):**
112
113 ```rust
114 use maxminddb::WithinOptions;
115
116 for result in reader.within(cidr, Default::default())? {
117 let result = result?;
118 let network = result.network()?;
119 if let Some(city) = result.decode::<geoip2::City>()? {
120 println!("{}: {:?}", network, city);
121 }
122 }
123 ```
124
125 To customize iteration behavior:
126
127 ```rust
128 let options = WithinOptions::default()
129 .include_aliased_networks() // Include IPv4 via IPv6 aliases
130 .include_networks_without_data() // Include networks without data
131 .skip_empty_values(); // Skip empty maps/arrays
132
133 for result in reader.within(cidr, options)? {
134 // ...
135 }
136 ```
137
138 ### GeoIP2 Name Fields
139
140 The `names` fields now use a `Names` struct instead of `BTreeMap`.
141
142 **Before (0.26):**
143
144 ```rust
145 let name = city.city
146 .as_ref()
147 .and_then(|c| c.names.as_ref())
148 .and_then(|n| n.get("en"));
149 ```
150
151 **After (0.27):**
152
153 ```rust
154 let name = city.city.names.english;
155 ```
156
157 Available language fields:
158
159 - `german`
160 - `english`
161 - `spanish`
162 - `french`
163 - `japanese`
164 - `brazilian_portuguese`
165 - `russian`
166 - `simplified_chinese`
167
168 ### GeoIP2 Nested Structs
169
170 Nested struct fields are now non-optional with `Default`.
171
172 **Before (0.26):**
173
174 ```rust
175 let iso_code = city.country
176 .as_ref()
177 .and_then(|c| c.iso_code.as_ref());
178
179 let subdivisions = city.subdivisions
180 .as_ref()
181 .map(|v| v.iter())
182 .into_iter()
183 .flatten();
184 ```
185
186 **After (0.27):**
187
188 ```rust
189 let iso_code = city.country.iso_code;
190
191 for subdivision in &city.subdivisions {
192 // ...
193 }
194 ```
195
196 Leaf values (strings, numbers, bools) remain `Option<T>`.
197
198 ### Removed Trait Fields
199
200 The `is_anonymous_proxy` and `is_satellite_provider` fields have been removed
201 from `country::Traits` and `enterprise::Traits`. These fields are no longer
202 present in MaxMind databases.
203
204 For anonymity detection, use the [Anonymous IP database](https://www.maxmind.com/en/geoip2-anonymous-ip-database).
205
206 ### Error Types
207
208 Error variants now use structured fields.
209
210 **Before (0.26):**
211
212 ```rust
213 match error {
214 MaxMindDbError::InvalidDatabase(msg) => {
215 println!("Invalid database: {}", msg);
216 }
217 // ...
218 }
219 ```
220
221 **After (0.27):**
222
223 ```rust
224 match error {
225 MaxMindDbError::InvalidDatabase { message, offset } => {
226 println!("Invalid database: {} at {:?}", message, offset);
227 }
228 MaxMindDbError::InvalidInput { message } => {
229 println!("Invalid input: {}", message);
230 }
231 // ...
232 }
233 ```
234
235 The new `InvalidInput` variant is used for user errors like looking up an IPv6
236 address in an IPv4-only database.
237
238 ### Quick Migration Checklist
239
240 1. Update `lookup()` calls to use `.decode::<T>()?`
241 2. Replace `lookup_prefix()` with `lookup()` + `network()`
242 3. Add `Default::default()` as second argument to `within()`
243 4. Update `within()` loops to use `result.network()` and `result.decode()`
244 5. Replace `names.get("en")` with `names.english`
245 6. Remove `.as_ref()` chains for nested GeoIP2 fields
246 7. Remove references to `is_anonymous_proxy` and `is_satellite_provider`
247 8. Update error matching to use struct patterns