pub struct GtfsReader {
    pub read_stop_times: bool,
    pub read_shapes: bool,
    pub unkown_enum_as_default: bool,
    pub trim_fields: bool,
}
Expand description

Allows to parameterize how the parsing library behaves

let gtfs = gtfs_structures::GtfsReader::default()
   .read_stop_times(false) // Won’t read the stop times to save time and memory
   .read_shapes(false) // Won’t read shapes to save time and memory
   .unkown_enum_as_default(false) // Won’t convert unknown enumerations into default (e.g. LocationType=42 considered as a stop point)
   .read("fixtures/zips/gtfs.zip")?;
assert_eq!(0, gtfs.trips.get("trip1").unwrap().stop_times.len());

You can also get a RawGtfs by doing

let gtfs = gtfs_structures::GtfsReader::default()
   .read_stop_times(false)
   .raw()
   .read("fixtures/zips/gtfs.zip")?;
assert_eq!(1, gtfs.trips?.len());
assert_eq!(0, gtfs.stop_times?.len());

Fields§

§read_stop_times: bool

crate::objects::StopTime are very large and not always needed. This allows to skip reading them

§read_shapes: bool

crate::objects::Shape are very large and not always needed. This allows to skip reading them

§unkown_enum_as_default: bool

If a an enumeration has an unknown value, should we use the default value

§trim_fields: bool

Avoid trimming the fields

It is quite time consuming If performance is an issue, and if your data is high quality, you can switch it off

Implementations§

source§

impl GtfsReader

source

pub fn read_stop_times(self, read_stop_times: bool) -> Self

Configures the reader to read or not the stop times (default: true)

This can be useful to save time and memory with large datasets when the timetable are not needed Returns Self and can be chained

source

pub fn read_shapes(self, read_shapes: bool) -> Self

This can be useful to save time and memory with large datasets when shapes are not needed Returns Self and can be chained

source

pub fn unkown_enum_as_default(self, unkown_enum_as_default: bool) -> Self

If a an enumeration has un unknown value, should we use the default value (default: false)

For instance, if crate::objects::Stop has a crate::objects::LocationType with a value 42 in the GTFS when true, we will parse it as StopPoint when false, we will parse it as Unknown(42) Returns Self and can be chained

source

pub fn trim_fields(self, trim_fields: bool) -> Self

Should the fields be trimmed (default: true)

It is quite time consumming If performance is an issue, and if your data is high quality, you can set it to false

source

pub fn read(self, 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 read_from_path<P>(self, path: P) -> Result<Gtfs, Error>
where P: AsRef<Path> + Display,

 Reads the raw GTFS from a local zip archive or local directory

source

pub fn read_from_url<U: IntoUrl>(self, 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 read_from_url_async<U: IntoUrl>( self, 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 raw(self) -> RawGtfsReader

Read the Gtfs as a RawGtfs.

let gtfs = gtfs_structures::GtfsReader::default()
   .read_stop_times(false)
   .raw()
   .read("fixtures/zips/gtfs.zip")?;
assert_eq!(1, gtfs.trips?.len());
assert_eq!(0, gtfs.stop_times?.len());

Trait Implementations§

source§

impl Default for GtfsReader

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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