Struct Gtfs

Source
pub struct Gtfs {
    pub read_duration: Duration,
    pub calendar: HashMap<String, Calendar>,
    pub calendar_dates: HashMap<String, Vec<CalendarDate>>,
    pub stops: HashMap<String, Arc<Stop>>,
    pub routes: HashMap<String, Route>,
    pub trips: HashMap<String, Trip>,
    pub agencies: Vec<Agency>,
    pub shapes: HashMap<String, Vec<Shape>>,
    pub fare_attributes: HashMap<String, FareAttribute>,
    pub fare_rules: HashMap<String, Vec<FareRule>>,
    pub feed_info: Vec<FeedInfo>,
}
Expand description

Data structure with all the GTFS objects

This structure is easier to use than the RawGtfs structure as some relationships are parsed to be easier to use.

If you want to configure the behaviour (e.g. skipping : StopTime or Shape), see crate::GtfsReader for more personalisation

This is probably the entry point you want to use:

let gtfs = gtfs_structures::Gtfs::new("fixtures/zips/gtfs.zip")?;
assert_eq!(gtfs.stops.len(), 5);

The StopTime are accessible from the Trip

Fields§

§read_duration: Duration

Time needed to read and parse the archive

§calendar: HashMap<String, Calendar>

All Calendar by service_id

§calendar_dates: HashMap<String, Vec<CalendarDate>>

All calendar dates grouped by service_id

§stops: HashMap<String, Arc<Stop>>

All stop by stop_id. Stops are in an Arc because they are also referenced by each StopTime

§routes: HashMap<String, Route>

All routes by route_id

§trips: HashMap<String, Trip>

All trips by trip_id

§agencies: Vec<Agency>

All agencies. They can not be read by agency_id, as it is not a required field

§shapes: HashMap<String, Vec<Shape>>

All shapes by shape_id

§fare_attributes: HashMap<String, FareAttribute>

All fare attributes by fare_id

§fare_rules: HashMap<String, Vec<FareRule>>

All fare rules by fare_id

§feed_info: Vec<FeedInfo>

All feed information. There is no identifier

Implementations§

Source§

impl Gtfs

Source

pub fn print_stats(&self)

Prints on stdout some basic statistics about the GTFS file (numbers of elements for each object). Mostly to be sure that everything was read

Source

pub fn new(gtfs: &str) -> Result<Gtfs, Error>

Reads from an url (if starts with "http"), or a local path (either a directory or zipped file)

To read from an url, build with read-url feature See also Gtfs::from_url and Gtfs::from_path if you don’t want the library to guess

Source

pub fn from_path<P>(path: P) -> Result<Gtfs, Error>
where P: AsRef<Path>,

 Reads the GTFS from a local zip archive or local directory

Source

pub fn from_url<U: IntoUrl>(url: U) -> Result<Gtfs, Error>

Reads the GTFS from a remote url

The library must be built with the read-url feature

Source

pub async fn from_url_async<U: IntoUrl>(url: U) -> Result<Gtfs, Error>

Asynchronously reads the GTFS from a remote url

The library must be built with the read-url feature

Source

pub fn from_reader<T: Read + Seek>(reader: T) -> Result<Gtfs, Error>

Reads for any object implementing std::io::Read and std::io::Seek

Mostly an internal function that abstracts reading from an url or local file

Source

pub fn trip_days(&self, service_id: &str, start_date: NaiveDate) -> Vec<u16>

For a given a service_id and a starting date returns all the following day offset the vehicle runs

For instance if the start_date is 2021-12-20, [0, 4] means that the vehicle will run the 20th and 24th

It will consider use both Calendar and CalendarDate (both added and removed)

Source

pub fn get_stop<'a>(&'a self, id: &str) -> Result<&'a Stop, Error>

Gets a Stop by its stop_id

Source

pub fn get_trip<'a>(&'a self, id: &str) -> Result<&'a Trip, Error>

Gets a Trip by its trip_id

Source

pub fn get_route<'a>(&'a self, id: &str) -> Result<&'a Route, Error>

Gets a Route by its route_id

Source

pub fn get_calendar<'a>(&'a self, id: &str) -> Result<&'a Calendar, Error>

Gets a Calendar by its service_id

Source

pub fn get_calendar_date<'a>( &'a self, id: &str, ) -> Result<&'a Vec<CalendarDate>, Error>

Gets all CalendarDate of a service_id

Source

pub fn get_shape<'a>(&'a self, id: &str) -> Result<&'a Vec<Shape>, Error>

Gets all Shape points of a shape_id

Source

pub fn get_fare_attributes<'a>( &'a self, id: &str, ) -> Result<&'a FareAttribute, Error>

Gets a FareAttribute by its fare_id

Trait Implementations§

Source§

impl Default for Gtfs

Source§

fn default() -> Gtfs

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

impl TryFrom<RawGtfs> for Gtfs

Source§

fn try_from(raw: RawGtfs) -> Result<Gtfs, Error>

Tries to build a Gtfs from a RawGtfs

It might fail if some mandatory files couldn’t be read or if there are references to other objects that are invalid.

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl Freeze for Gtfs

§

impl RefUnwindSafe for Gtfs

§

impl Send for Gtfs

§

impl Sync for Gtfs

§

impl Unpin for Gtfs

§

impl UnwindSafe for Gtfs

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T