Skip to main content

AirportData

Struct AirportData 

Source
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

Source

pub fn new() -> Self

Creates a new AirportData instance.

This is cheap — data is loaded lazily on first query.

Source

pub fn all_airports(&self) -> &[Airport]

Returns a reference to all airports in the database.

Source

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"));
Source

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).

Source

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.

Source

pub fn get_airports_by_icao(&self, icao_code: &str) -> Vec<&Airport>

Finds all airports matching a 4-letter ICAO code.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn get_airports_by_country_code(&self, country_code: &str) -> Vec<&Airport>

Finds all airports in a specific country.

Source

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

Source

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).

Source

pub fn get_airports_by_timezone(&self, timezone: &str) -> Vec<&Airport>

Finds all airports within a specific timezone.

Source

pub fn find_airports(&self, filter: &AirportFilter) -> Vec<&Airport>

Finds airports matching multiple criteria.

Source

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.

Gets external links for an airport.

Accepts either IATA or ICAO code.

Source

pub fn get_airport_stats_by_country( &self, country_code: &str, ) -> Result<CountryStats>

Gets comprehensive statistics about airports in a specific country.

Source

pub fn get_airport_stats_by_continent( &self, continent_code: &str, ) -> Result<ContinentStats>

Gets comprehensive statistics about airports on a specific continent.

Source

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".

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_airport_operational(&self, code: &str) -> Result<bool>

Checks if an airport has scheduled commercial service.

Accepts either IATA or ICAO code.

Trait Implementations§

Source§

impl Default for AirportData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.