Skip to main content

Crate hafas

Crate hafas 

Source
Expand description

Client for the HAFAS ReST public transport API.

The types follow the dialect versions DIALECT_VERSIONS of the API and read both: fields that only one of them sends are optional. They cover location search, departure and arrival boards, trip search, journey details and the reconstruction of a trip.

The crate is neutral towards the operator: it has no default base URL and no policy for the access key.

use hafas::{Client, LocationName};

let client = Client::builder("https://hafas.example.org/api/")
    .access_id("secret")
    .user_agent("my-app/1.0 (+https://example.org)")
    .build()?;
let list = client.send(&LocationName::new("Hauptwache")).await?;
for stop in list.stops() {
    println!("{} {}", stop.ext_id, stop.name);
}

The access key is a query parameter, so every request URL contains it. The client keeps it out of everything it returns or logs: Client::url leaves it out, errors carry no URL, and texts of the API that echo the key have it replaced by REDACTED.

The client sends every request once. It does not retry, and it does not cache: that is up to the caller.

Structs§

Arrival
An arrival of an arrival board.
ArrivalBoard
The arrivals at a stop (arrivalBoard).
ArrivalList
The answer of arrivalBoard.
BoardEvent
What departures and arrivals have in common.
Client
A client for one HAFAS server.
ClientBuilder
Configures a Client.
CoordLocation
An address, a point of interest or a coordinate.
Departure
A departure of a departure board.
DepartureBoard
The departures at a stop (departureBoard).
DepartureList
The answer of departureBoard.
Direction
A direction a journey shows on part of its route.
Journey
One journey with its stops: the answer of journeyDetail, and part of a leg (JourneyDetail).
JourneyDetail
One journey with all its stops (journeyDetail).
JourneyDetailRef
A reference to a journey, for JourneyDetail.
Leg
A leg of a trip: a journey, a walk or a transfer.
LocationList
The answer of location.name and location.nearbystops.
LocationName
Finds locations by name (location.name).
LocationNote
A note on a location.
Message
A message about a disruption or a change (from HIM).
Name
A name a journey has on part of its route.
NearbyStops
Finds stops near a position (location.nearbystops).
Note
A note on a stop, a journey or a part of it.
Occupancy
How full a vehicle is expected to be.
OriginDest
The start or the end of a trip or a leg (OriginDestType).
Platform
A platform, a stand or the like.
Product
A line or a vehicle (ProductType).
Recon
Checks a trip again with current data (recon).
ResponseInfo
What every response says about itself (CommonResponseType).
ServiceDays
The days a journey or a trip runs.
Stop
A stop of a journey (StopType).
StopLocation
A stop or station.
Trip
A connection between two places (TripType).
TripList
The answer of trip and recon.
TripSearch
Searches connections between two places (trip).
TripStatus
Remarks of the server on a trip.
Url
A parsed URL record.

Enums§

Error
What can go wrong talking to the API.
JourneyStatus
What kind of journey a departure, an arrival or a leg is (JourneyStatusType).
Location
A match of a location search.
LocationKind
What kind of place a location is: a stop, an address, a point of interest or a coordinate.
Place
Where a trip starts or ends.
PlatformKind
What a platform text names (PlatformTypeType).
PrognosisType
Where a real-time time comes from (PrognosisType).
RtMode
How much real-time data a search takes into account (rtMode).

Constants§

DEFAULT_TIMEOUT
The default time to wait for a response.
DIALECT_VERSIONS
The dialect versions of the API this crate reads.
REDACTED
What stands in for the access key in texts of the API that echo it.

Traits§

Request
A request to one service, sent with Client::send.