Struct Client

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Source

pub fn with_base_url(base_url: &str) -> Self

Source

pub async fn arrivals( &self, request: ArrivalsRequest, ) -> Result<ArrivalsResponse>

Returns a list of regional rail trains to arrive at a given station

This function calls into the /Arrivals/index.php endpoint.

The returned list is split into northbound and southbound trains. The definition of “Northbound” and “Southbound” is defined by SEPTA as the following: The direction are obviously not geographical references, but rather a reference to the old Reading and Pennsy Railroads. The key to understanding the direction is by using Suburban Station as a starting point: Any trains that move eastbound towards Market East are all considered Northbound; trains going from suburban to 30th St are all Southbound. The path field describes more accurately the path of travel along various branches.

§Arguments
  • request - A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::ArrivalsRequest;
use septa_api::types::RegionalRailStop;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let request = ArrivalsRequest {
        station: RegionalRailStop::SuburbanStation,
        results: Some(5),
        direction: None
    };
    let response = client.arrivals(request).await?;

    // Loop through the northbound arrivals
    for train in response.northbound {
        println!("Train {} is currently {} on the {} line", train.train_id, train.status, train.line.to_string());
    }

    // Loop through the southbound arrivals
    for train in response.southbound {
        println!("Train {} is currently {} on the {} line", train.train_id, train.status, train.line.to_string());
    }

    Ok(())
}
Source

pub async fn train_view(&self) -> Result<TrainResponse>

Returns a list of all active regional rail trains

This function calls into the /TrainView/index.php endpoint.

§Example
use septa_api::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let response = client.train_view().await?;

    for train in response {
        println!("Train {} is currently {} mins late on the {} line", train.train_number, train.late, train.line.to_string());
    }

    Ok(())
}
Source

pub async fn next_to_arrive( &self, request: NextToArriveRequest, ) -> Result<NextToArriveResponse>

Returns departure and arrival times between two different stations

This function calls into the /NextToArrive/index.php endpoint.

§Arguments
  • request - A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::NextToArriveRequest;
use septa_api::types::RegionalRailStop;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let request = NextToArriveRequest {
        starting_station: RegionalRailStop::SuburbanStation,
        ending_station: RegionalRailStop::Downingtown,
        results: None,
    };
    let response = client.next_to_arrive(request).await?;

    for next_to_arrive in response {
       println!("Train {} is scheduled to arrive {}", next_to_arrive.orig_train, next_to_arrive.orig_departure_time);
    }

   Ok(())
}
Source

pub async fn rail_schedule( &self, request: RailScheduleRequest, ) -> Result<RailScheduleResponse>

Returns the schedule for a train by the train’s number

This function calls into the /RRSchedules/index.php endpoint.

§Arguments
  • request - A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::RailScheduleRequest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let request = RailScheduleRequest {
        train_number: "514".to_string()
    };
    let response = client.rail_schedule(request).await?;

    for schedule in response {
       println!("The train is scheduled to arrive at {} at {}", schedule.station.to_string(), schedule.scheduled_time);
    }

   Ok(())
}

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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,