Skip to content

Commit

Permalink
feat: (#45) Relax Sync + Send requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
zeon256 committed Mar 2, 2024
1 parent 435d399 commit d18c3f0
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 74 deletions.
18 changes: 12 additions & 6 deletions src/async/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ pub trait BusRequests<C: Client + ClientExt> {
where
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/BusServices");
client
.build_req_with_skip::<BusServiceResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<BusServiceResp, _>(
&concat_string!(client.base_url(), "/BusServices"),
skip.into(),
)
.await
}

Expand All @@ -48,9 +50,11 @@ pub trait BusRequests<C: Client + ClientExt> {
where
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/BusRoutes");
client
.build_req_with_skip::<BusRouteResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<BusRouteResp, _>(
&concat_string!(client.base_url(), "/BusRoutes"),
skip.into(),
)
.await
}

Expand All @@ -62,9 +66,11 @@ pub trait BusRequests<C: Client + ClientExt> {
where
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/BusStops");
client
.build_req_with_skip::<BusStopsResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<BusStopsResp, _>(
&concat_string!(client.base_url(), "/BusStops"),
skip.into(),
)
.await
}
}
6 changes: 3 additions & 3 deletions src/async/crowd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use time::Date;
use super::ClientExt;

/// All APIs pertaining to transportation crowd
pub trait CrowdRequests<C: Client + ClientExt + Send> {
pub trait CrowdRequests<C: Client + ClientExt> {
/// **Update freq**: By 15th of every month, the passenger volume for previous month data
/// will be generated
///
Expand All @@ -20,8 +20,8 @@ pub trait CrowdRequests<C: Client + ClientExt + Send> {
skip: S,
) -> LTAResult<Vec<String>>
where
S: Into<Option<u32>> + Send,
D: Into<Option<Date>> + Send;
S: Into<Option<u32>>,
D: Into<Option<Date>>;

/// Returns real-time platform crowdedness level for the MRT/LRT stations of a
/// particular train network line
Expand Down
2 changes: 1 addition & 1 deletion src/async/facility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{Client, LTAResult};

use super::ClientExt;

pub trait FacilityRequests<C: Client + ClientExt + Send> {
pub trait FacilityRequests<C: Client + ClientExt> {
/// Returns pre-signed links to JSON file containing facilities maintenance schedules of the particular station
///
/// **Update Freq**: Adhoc
Expand Down
2 changes: 1 addition & 1 deletion src/async/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ClientExt;
use crate::models::geo::prelude::*;
use crate::{Client, LTAResult};

pub trait GeoRequests<C: Client + ClientExt + Send> {
pub trait GeoRequests<C: Client + ClientExt> {
/// Returns the SHP files of the requested geospatial layer
///
/// **Update Freq**: Adhoc
Expand Down
18 changes: 11 additions & 7 deletions src/async/taxi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ use crate::{Client, LTAResult};
use concat_string::concat_string;

/// All APIs pertaining to taxis
pub trait TaxiRequests<C: Client + ClientExt + Send> {
pub trait TaxiRequests<C: Client + ClientExt> {
/// Returns location coordinates of all Taxis that are currently available for
/// hire. Does not include "Hired" or "Busy" Taxis.
///
/// **Update freq**: 1min
async fn get_taxi_avail<S>(client: &C, skip: S) -> LTAResult<Vec<Coordinates>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/Taxi-Availability");
client
.build_req_with_skip::<TaxiAvailResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<TaxiAvailResp, _>(
&concat_string!(client.base_url(), "/Taxi-Availability"),
skip.into(),
)
.await
}

Expand All @@ -25,11 +27,13 @@ pub trait TaxiRequests<C: Client + ClientExt + Send> {
/// **Update freq**: Monthly
async fn get_taxi_stands<S>(client: &C, skip: S) -> LTAResult<Vec<TaxiStand>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/TaxiStands");
client
.build_req_with_skip::<TaxiStandsResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<TaxiStandsResp, _>(
&concat_string!(client.base_url(), "/TaxiStands"),
skip.into(),
)
.await
}
}
48 changes: 29 additions & 19 deletions src/async/traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ use concat_string::concat_string;

use super::ClientExt;

pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
pub trait TrafficRequests<C: Client + ClientExt> {
/// Returns ERP rates of all vehicle types across all timings for each
/// zone.
///
/// **Update freq**: Ad-Hoc
async fn get_erp_rates<S>(client: &C, skip: S) -> LTAResult<Vec<ErpRate>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/ERPRates");
client
.build_req_with_skip::<ErpRatesResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<ErpRatesResp, _>(
&concat_string!(client.base_url(), "/ERPRates"),
skip.into(),
)
.await
}

Expand All @@ -28,11 +30,13 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
/// **Update freq**: 1 min
async fn get_carpark_avail<S>(client: &C, skip: S) -> LTAResult<Vec<CarPark>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/CarParkAvailabilityv2");
client
.build_req_with_skip::<CarparkAvailResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<CarparkAvailResp, _>(
&concat_string!(client.base_url(), "/CarParkAvailabilityv2"),
skip.into(),
)
.await
}

Expand All @@ -41,11 +45,13 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
/// **Update freq**: 5min
async fn get_est_travel_time<S>(client: &C, skip: S) -> LTAResult<Vec<EstTravelTime>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/EstTravelTimes");
client
.build_req_with_skip::<EstTravelTimeResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<EstTravelTimeResp, _>(
&concat_string!(client.base_url(), "/EstTravelTimes"),
skip.into(),
)
.await
}

Expand All @@ -55,11 +61,13 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
/// **Update freq**: 2min or whenever there are updates
async fn get_faulty_traffic_lights<S>(client: &C, skip: S) -> LTAResult<Vec<FaultyTrafficLight>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/FaultyTrafficLights");
client
.build_req_with_skip::<FaultyTrafficLightResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<FaultyTrafficLightResp, _>(
&concat_string!(client.base_url(), "/FaultyTrafficLights"),
skip.into(),
)
.await
}

Expand All @@ -72,7 +80,7 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
skip: S,
) -> LTAResult<Vec<RoadDetails>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = match road_details_type {
RoadDetailsType::RoadOpening => concat_string!(client.base_url(), "/RoadOpenings"),
Expand All @@ -81,7 +89,7 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
};

client
.build_req_with_skip::<RoadDetailsResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<RoadDetailsResp, _>(&url, skip.into())
.await
}

Expand All @@ -91,11 +99,13 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
/// **Update freq**: 5 minutes
async fn get_traffic_speed_band<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficSpeedBand>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/v3/TrafficSpeedBands");
client
.build_req_with_skip::<TrafficSpeedBandResp, _>(url.as_str(), skip.into())
.build_req_with_skip::<TrafficSpeedBandResp, _>(
&concat_string!(client.base_url(), "/v3/TrafficSpeedBands"),
skip.into(),
)
.await
}

Expand All @@ -105,7 +115,7 @@ pub trait TrafficRequests<C: Client + ClientExt + Send + Sync> {
/// **Update freq**: 1 to 5 minutes
async fn get_traffic_images<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficImage>>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/Traffic-Imagesv2");
client
Expand Down
10 changes: 6 additions & 4 deletions src/async/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ use concat_string::concat_string;

use super::ClientExt;

pub trait TrainRequests<C: Client + ClientExt + Send + Sync> {
pub trait TrainRequests<C: Client + ClientExt> {
/// Returns detailed information on train service unavailability during scheduled
/// operating hours, such as affected line and stations etc.
///
/// **Update freq**: ad-hoc
async fn get_train_service_alert<S>(client: &C, skip: S) -> LTAResult<TrainServiceAlert>
where
S: Into<Option<u32>> + Send,
S: Into<Option<u32>>,
{
let url = concat_string!(client.base_url(), "/TrainServiceAlerts");
client
.build_req_with_skip::<TrainServiceAlertResp, _>(url.as_ref(), skip.into())
.build_req_with_skip::<TrainServiceAlertResp, _>(
&concat_string!(client.base_url(), "/TrainServiceAlerts"),
skip.into(),
)
.await
}
}
4 changes: 2 additions & 2 deletions src/reqwest_async/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl BusRequests<LTAClient<ReqwestAsync>> for Bus {
match service_no.into() {
Some(srv_no) => {
client
.build_req_with_query::<RawBusArrivalResp, _, _>(url.as_str(), |rb| {
.build_req_with_query::<RawBusArrivalResp, _, _>(&url, |rb| {
rb.query(&[
("BusStopCode", bus_stop_code.to_string().as_str()),
("ServiceNo", srv_no),
Expand All @@ -29,7 +29,7 @@ impl BusRequests<LTAClient<ReqwestAsync>> for Bus {
}
None => {
client
.build_req_with_query::<RawBusArrivalResp, _, _>(url.as_str(), |rb| {
.build_req_with_query::<RawBusArrivalResp, _, _>(&url, |rb| {
rb.query(&[("BusStopCode", bus_stop_code.to_string())])
})
.await
Expand Down
32 changes: 14 additions & 18 deletions src/reqwest_async/crowd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl CrowdRequests<LTAClient<ReqwestAsync>> for Crowd {
skip: S,
) -> LTAResult<Vec<String>>
where
S: Into<Option<u32>> + Send,
D: Into<Option<Date>> + Send,
S: Into<Option<u32>>,
D: Into<Option<Date>>,
{
let format = format_description!("[year]-[month]-[day]");
let fmt_date = date
Expand All @@ -36,18 +36,14 @@ impl CrowdRequests<LTAClient<ReqwestAsync>> for Crowd {
match fmt_date {
Some(nd) => {
client
.build_req_with_query::<passenger_vol::PassengerVolRawResp, _, _>(
url.as_str(),
|rb| rb.query(&[("Date", nd)]),
)
.build_req_with_query::<passenger_vol::PassengerVolRawResp, _, _>(&url, |rb| {
rb.query(&[("Date", nd)])
})
.await
}
None => {
client
.build_req_with_skip::<passenger_vol::PassengerVolRawResp, _>(
url.as_str(),
skip.into(),
)
.build_req_with_skip::<passenger_vol::PassengerVolRawResp, _>(&url, skip.into())
.await
}
}
Expand All @@ -57,23 +53,23 @@ impl CrowdRequests<LTAClient<ReqwestAsync>> for Crowd {
client: &LTAClient<ReqwestAsync>,
train_line: MrtLine,
) -> LTAResult<Vec<StationCrowdLevel>> {
let url = concat_string!(client.base_url(), "/PCDRealTime");
client
.build_req_with_query::<StationCrowdLevelRawResp, _, _>(url.as_str(), |rb| {
rb.query(&[("TrainLine", train_line)])
})
.build_req_with_query::<StationCrowdLevelRawResp, _, _>(
&concat_string!(client.base_url(), "/PCDRealTime"),
|rb| rb.query(&[("TrainLine", train_line)]),
)
.await
}

async fn get_crowd_density_forecast(
client: &LTAClient<ReqwestAsync>,
train_line: MrtLine,
) -> LTAResult<CrowdDensityForecast> {
let url = concat_string!(client.base_url(), "/PCDForecast");
client
.build_req_with_query::<CrowdDensityForecastRawResp, _, _>(url.as_str(), |rb| {
rb.query(&[("TrainLine", train_line)])
})
.build_req_with_query::<CrowdDensityForecastRawResp, _, _>(
&concat_string!(client.base_url(), "/PCDForecast"),
|rb| rb.query(&[("TrainLine", train_line)]),
)
.await
}
}
8 changes: 4 additions & 4 deletions src/reqwest_async/facility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ impl FacilityRequests<LTAClient<ReqwestAsync>> for Facility {
client: &LTAClient<ReqwestAsync>,
station_code: StationCode,
) -> LTAResult<Vec<String>> {
let url = concat_string!(client.base_url(), "/FacilitiesMaintenance");
client
.build_req_with_query::<FacilityMaintenanceRawResp, _, _>(url.as_str(), |rb| {
rb.query(&[("StationCode", station_code)])
})
.build_req_with_query::<FacilityMaintenanceRawResp, _, _>(
&concat_string!(client.base_url(), "/FacilitiesMaintenance"),
|rb| rb.query(&[("StationCode", station_code)]),
)
.await
}
}
8 changes: 4 additions & 4 deletions src/reqwest_async/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ impl GeoRequests<LTAClient<ReqwestAsync>> for Geo {
client: &LTAClient<ReqwestAsync>,
id: GeospatialLayerId,
) -> LTAResult<Vec<String>> {
let url = concat_string!(client.base_url(), "/GeospatialWholeIsland");
client
.build_req_with_query::<GeospatialWholeIslandRawResp, _, _>(url.as_str(), |rb| {
rb.query(&[("ID", id)])
})
.build_req_with_query::<GeospatialWholeIslandRawResp, _, _>(
&concat_string!(client.base_url(), "/GeospatialWholeIsland"),
|rb| rb.query(&[("ID", id)]),
)
.await
}
}
Loading

0 comments on commit d18c3f0

Please sign in to comment.