Skip to main content

Crate gatelogue_types

Crate gatelogue_types 

Source
Expand description

Rust utility library for using Gatelogue data in Rust projects. It will load the database for you to access via ORM or raw SQL.

§Installation

Add to your Cargo.toml:

gatelogue-types = { version = "3", features = [...] }

# To import directly from the repository:
gatelogue-types = { git = "https://github.com/mrt-map/gatelogue", package = "gatelogue-types", features = [...] }

Add the bundled feature to bundle SQLite.

Also add an HTTP client (e.g. reqwest, ureq) of your choice.

§Usage

To retrieve the data:

use gatelogue_types::{GD, getter};
// with pre-written getter!() functions:
let gd = GD::get_async_no_sources(getter!(reqwest)).await?; // retrieve data (async)
let gd = GD::get_no_sources(getter!(ureq))?; // retrieve data (blocking)

// or with any HTTP client of your choice (with a callable that takes in a &str and returns an AsRef<[u8]>):
let gd = GD::get_async_no_sources(async |url| reqwest::Result::Ok(reqwest::get(url).await?.bytes().await?.to_vec())); // retrieve data (async)
let gd = GD::get_no_sources(|url| ureq::get(url).call()?.into_body().read_to_vec())?; // retrieve data (blocking)

// similar syntax can be used if you want the sources, with `get_async_with_sources` and `get_with_sources`

getter!() accepts the following inputs:

  • reqwest (async) requiring reqwest
  • reqwest_blocking (blocking) requiring reqwest with blocking feature
  • surf (async) requiring surf
  • ureq (blocking) requiring ureq
  • isahc (blocking) requiring isahc
  • isahc_async (async) requiring isahc
  • attohttpc (blocking) requiring attohttpc (untested)
  • minreq (blocking) requiring minreq
  • wreq (async) requiring wreq
  • ehttp (blocking) requiring ehttp
  • ehttp_async (async) requiring ehttp with native_async feature

Using the ORM does not require SQL and makes for generally clean code. However, doing this is very inefficient as each attribute access is one SQL query.

use gatelogue_types::AirAirport;
for airport in gd.nodes_of_type::<AirAirport>()? {
    for gate in airport.gates(&gd)? {
        println!("Airport {:?} has gate {:?}", airport.code(&gd)?, gate.code(&gd)?)
    }
}

Querying the underlying SQLite database directly with rusqlite is generally more efficient and faster. It is also the only way to access the *Source tables, if you retrieved the database with those.

gd.0.prepare("SELECT A.code, G.code FROM AirGate G INNER JOIN AirAirport A ON G.airport = A.i")?
    .query_map((), |row| {
        println!("Airport {:?} has gate {:?}", row.get::<_, String>(0)?, row.get::<_, String>(1)?);
        Ok(())
    })?;

Macros§

get_aircraft_column
getter
node_type

Structs§

AirAirline
AirAirport
AirFlight
AirGate
Aircraft
BusBerth
BusCompany
BusConnection
BusLine
BusStop
GD
Proximity
RailCompany
RailConnection
RailLine
RailPlatform
RailStation
SeaCompany
SeaConnection
SeaDock
SeaLine
SeaStop
SpawnWarp
Town

Enums§

AirMode
AnyLocatedNode
AnyNode
BusMode
Error
RailMode
Rank
SeaMode
WarpType
World

Constants§

URL
URL_NO_SOURCES

Traits§

LocatedNode
Node

Type Aliases§

ID
Result