pub struct AirportData;Expand description
The main entry point for querying airport data.
All data is loaded lazily on first access and cached for the lifetime of
the process. The AirportData struct itself is zero-cost to create — it
just provides methods to query the shared global data.
Implementations§
Source§impl AirportData
impl AirportData
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new AirportData instance.
This is cheap — data is loaded lazily on first query.
Sourcepub fn all_airports(&self) -> &[Airport]
pub fn all_airports(&self) -> &[Airport]
Returns a reference to all airports in the database.
Sourcepub fn get_airport_by_iata(&self, iata_code: &str) -> Result<&Airport>
pub fn get_airport_by_iata(&self, iata_code: &str) -> Result<&Airport>
Finds an airport by its 3-letter IATA code.
Returns the first matching airport, or an error if not found.
§Example
use airport_data::AirportData;
let db = AirportData::new();
let airport = db.get_airport_by_iata("LHR").unwrap();
assert!(airport.airport.contains("Heathrow"));Sourcepub fn get_airports_by_iata(&self, iata_code: &str) -> Vec<&Airport>
pub fn get_airports_by_iata(&self, iata_code: &str) -> Vec<&Airport>
Finds all airports matching a 3-letter IATA code.
Returns a Vec of references (usually 0 or 1 results).
Sourcepub fn get_airport_by_icao(&self, icao_code: &str) -> Result<&Airport>
pub fn get_airport_by_icao(&self, icao_code: &str) -> Result<&Airport>
Finds an airport by its 4-letter ICAO code.
Returns the first matching airport, or an error if not found.
Sourcepub fn get_airports_by_icao(&self, icao_code: &str) -> Vec<&Airport>
pub fn get_airports_by_icao(&self, icao_code: &str) -> Vec<&Airport>
Finds all airports matching a 4-letter ICAO code.
Sourcepub fn search_by_name(&self, query: &str) -> Result<Vec<&Airport>>
pub fn search_by_name(&self, query: &str) -> Result<Vec<&Airport>>
Searches for airports by name (case-insensitive partial match).
Query must be at least 2 characters.
Sourcepub fn find_nearby_airports(
&self,
lat: f64,
lon: f64,
radius_km: f64,
) -> Vec<NearbyAirport>
pub fn find_nearby_airports( &self, lat: f64, lon: f64, radius_km: f64, ) -> Vec<NearbyAirport>
Finds airports within a specified radius (km) of given coordinates.
Results are sorted by distance (nearest first).
Sourcepub fn calculate_distance(&self, code1: &str, code2: &str) -> Result<f64>
pub fn calculate_distance(&self, code1: &str, code2: &str) -> Result<f64>
Calculates the great-circle distance between two airports in kilometers.
Accepts either IATA or ICAO codes.
Sourcepub fn find_nearest_airport(
&self,
lat: f64,
lon: f64,
filter: Option<&AirportFilter>,
) -> Result<NearbyAirport>
pub fn find_nearest_airport( &self, lat: f64, lon: f64, filter: Option<&AirportFilter>, ) -> Result<NearbyAirport>
Finds the single nearest airport to given coordinates.
Optionally applies filters to narrow the search.
Sourcepub fn get_airports_by_country_code(&self, country_code: &str) -> Vec<&Airport>
pub fn get_airports_by_country_code(&self, country_code: &str) -> Vec<&Airport>
Finds all airports in a specific country.
Sourcepub fn get_airports_by_continent(&self, continent_code: &str) -> Vec<&Airport>
pub fn get_airports_by_continent(&self, continent_code: &str) -> Vec<&Airport>
Finds all airports on a specific continent.
Continent codes: AS, EU, NA, SA, AF, OC, AN
Sourcepub fn get_airports_by_type(&self, airport_type: &str) -> Vec<&Airport>
pub fn get_airports_by_type(&self, airport_type: &str) -> Vec<&Airport>
Finds airports by their type.
Types: large_airport, medium_airport, small_airport, heliport,
seaplane_base. Use "airport" to match all airport types (large,
medium, small).
Sourcepub fn get_airports_by_timezone(&self, timezone: &str) -> Vec<&Airport>
pub fn get_airports_by_timezone(&self, timezone: &str) -> Vec<&Airport>
Finds all airports within a specific timezone.
Sourcepub fn find_airports(&self, filter: &AirportFilter) -> Vec<&Airport>
pub fn find_airports(&self, filter: &AirportFilter) -> Vec<&Airport>
Finds airports matching multiple criteria.
Sourcepub fn get_autocomplete_suggestions(&self, query: &str) -> Vec<&Airport>
pub fn get_autocomplete_suggestions(&self, query: &str) -> Vec<&Airport>
Provides autocomplete suggestions for search interfaces.
Returns up to 10 airports matching the query by name or IATA code. Query must be at least 2 characters.
Sourcepub fn get_airport_links(&self, code: &str) -> Result<AirportLinks>
pub fn get_airport_links(&self, code: &str) -> Result<AirportLinks>
Gets external links for an airport.
Accepts either IATA or ICAO code.
Sourcepub fn get_airport_stats_by_country(
&self,
country_code: &str,
) -> Result<CountryStats>
pub fn get_airport_stats_by_country( &self, country_code: &str, ) -> Result<CountryStats>
Gets comprehensive statistics about airports in a specific country.
Sourcepub fn get_airport_stats_by_continent(
&self,
continent_code: &str,
) -> Result<ContinentStats>
pub fn get_airport_stats_by_continent( &self, continent_code: &str, ) -> Result<ContinentStats>
Gets comprehensive statistics about airports on a specific continent.
Sourcepub fn get_largest_airports_by_continent(
&self,
continent_code: &str,
limit: usize,
sort_by: &str,
) -> Vec<Airport>
pub fn get_largest_airports_by_continent( &self, continent_code: &str, limit: usize, sort_by: &str, ) -> Vec<Airport>
Gets the largest airports on a continent sorted by runway length or elevation.
sort_by can be "runway" (default) or "elevation".
Sourcepub fn get_multiple_airports(&self, codes: &[&str]) -> Vec<Option<&Airport>>
pub fn get_multiple_airports(&self, codes: &[&str]) -> Vec<Option<&Airport>>
Fetches multiple airports by their IATA or ICAO codes.
Returns None for codes that are not found.
Sourcepub fn calculate_distance_matrix(
&self,
codes: &[&str],
) -> Result<DistanceMatrix>
pub fn calculate_distance_matrix( &self, codes: &[&str], ) -> Result<DistanceMatrix>
Calculates distances between all pairs of airports in a list.
Requires at least 2 valid codes.
Sourcepub fn validate_iata_code(&self, code: &str) -> bool
pub fn validate_iata_code(&self, code: &str) -> bool
Validates if an IATA code exists in the database.
Code must be exactly 3 uppercase letters.
Sourcepub fn validate_icao_code(&self, code: &str) -> bool
pub fn validate_icao_code(&self, code: &str) -> bool
Validates if an ICAO code exists in the database.
Code must be exactly 4 uppercase alphanumeric characters.
Sourcepub fn get_airport_count(&self, filter: Option<&AirportFilter>) -> usize
pub fn get_airport_count(&self, filter: Option<&AirportFilter>) -> usize
Gets the count of airports matching the given filters.
Pass None for total count of all airports.
Sourcepub fn is_airport_operational(&self, code: &str) -> Result<bool>
pub fn is_airport_operational(&self, code: &str) -> Result<bool>
Checks if an airport has scheduled commercial service.
Accepts either IATA or ICAO code.