Get the next phone number in the sequence
(&mut self)
| 290 | |
| 291 | /// Get the next phone number in the sequence |
| 292 | pub fn next(&mut self) -> Option<String> { |
| 293 | if !self.has_more { |
| 294 | return None; |
| 295 | } |
| 296 | |
| 297 | // Keep generating numbers until we find one that matches our infix filter (if any) |
| 298 | loop { |
| 299 | // Use current area code and number |
| 300 | let area_code = &self.selected_area_codes[self.current_area_code_idx]; |
| 301 | let remaining_area_code_part = &self.remaining_area_code_parts[self.current_area_code_idx]; |
| 302 | |
| 303 | // Calculate the current number |
| 304 | let formatted_number = if let Some(suffix) = &self.suffix_filter { |
| 305 | // If we have a suffix, we'll generate the prefix part |
| 306 | // and append the suffix |
| 307 | let suffix_len = suffix.len(); |
| 308 | let prefix_len = self.digits_per_number - suffix_len; |
| 309 | |
| 310 | // Format the prefix part with proper padding |
| 311 | if prefix_len > 0 { |
| 312 | format!("{}{:0width$}{}", remaining_area_code_part, self.current_number, suffix, width = prefix_len) |
| 313 | } else { |
| 314 | // If we don't need to generate any additional digits, just use the remaining area code part and suffix |
| 315 | format!("{}{}", remaining_area_code_part, suffix) |
| 316 | } |
| 317 | } else { |
| 318 | // No suffix - format the full number with proper padding |
| 319 | format!("{}{:0width$}", remaining_area_code_part, self.current_number, width = self.digits_per_number) |
| 320 | }; |
| 321 | |
| 322 | // Increment for next call |
| 323 | self.current_number += 1; |
| 324 | if self.current_number >= self.max_numbers_per_segment { |
| 325 | self.current_number = 0; |
| 326 | self.current_area_code_idx += 1; |
| 327 | |
| 328 | if self.current_area_code_idx >= self.selected_area_codes.len() { |
| 329 | self.has_more = false; |
| 330 | // If we've run out of numbers and haven't found a match yet, return None |
| 331 | if self.infix_filter.is_some() { |
| 332 | return None; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Build the full phone number |
| 338 | let mut phone = format!("{}", self.country_code); |
| 339 | |
| 340 | if let Some(p) = &self.prefix { |
| 341 | // When prefix is provided, use it directly |
| 342 | phone.push_str(p); |
| 343 | } else { |
| 344 | // Otherwise use the area code |
| 345 | phone.push_str(area_code); |
| 346 | } |
| 347 | |
| 348 | // Append the formatted number |
| 349 | phone.push_str(&formatted_number); |
no outgoing calls