Skip to content

Commit

Permalink
feat: more impl Into<Type> parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
leontoeides committed Jun 9, 2024
1 parent eb9a061 commit f60f93e
Show file tree
Hide file tree
Showing 79 changed files with 351 additions and 190 deletions.
59 changes: 32 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,67 @@
* Release notes are available on
[GitHub](https://github.com/leontoeides/google_maps/releases).

# 3.5.3

* 2024-06-09: Increased flexibility of interface by using more `impl Into<Type>`
parameters.

* 2024-06-09: Clean-up of `tracing` messages, instrumentation and log levels.

# 3.5.2

* 3.5.2: 2024-06-05: New, optional `polyline` feature. This allows for easy
conversion of `google_maps` types (such as the `Route` and the `Step`) to a
* 2024-06-05: New, optional `polyline` feature. This allows for easy conversion
of `google_maps` types (such as the `Route` and the `Step`) to a
[geo](https://crates.io/crates/geo)
[LineString](https://docs.rs/geo-types/0.7.13/geo_types/geometry/struct.LineString.html).
Both the `polyline` and `geo` features must be enabled for these traits and
methods to be available.

* 3.5.2: 2024-06-05: Improved support for rust's
[geo](https://crates.io/crates/geo) eco-system with more type conversion
traits.
* 2024-06-05: Improved support for rust's [geo](https://crates.io/crates/geo)
eco-system with more type conversion traits.

# 3.5.1

* 3.5.1: 2024-06-04: Fixed some `Vec` fields by ensuring that the serde
`default` field attribute is applied to all `Vec` fields in response structs.
Thanks to [chunhui2001](https://github.com/chunhui2001) for the pull request
* 2024-06-04: Fixed some `Vec` fields by ensuring that the serde `default` field
attribute is applied to all `Vec` fields in response structs. Thanks to
[chunhui2001](https://github.com/chunhui2001) for the pull request
and to [PrinceOfBorgo](https://github.com/PrinceOfBorgo) for
[issue #27](https://github.com/leontoeides/google_maps/issues/27).

* 3.5.1: 2024-05-20: Added `duration` helper method to the
`PlaceOpeningHoursPeriod` type which will measure the length of the opening
hours period.
* 2024-05-20: Added `duration` helper method to the `PlaceOpeningHoursPeriod`
type which will measure the length of the opening hours period.

* 3.5.1: 2024-05-19: Improved `GoogleMapsClient` interface ergonomics. Client
methods now use `impl Into<Type>` and generics extensively. This means that
rust will automatically take care of many type conversions needed to build
your Google Maps requests.
* 2024-05-19: Improved `GoogleMapsClient` interface ergonomics. Client methods
now use `impl Into<Type>` and generics extensively. This means that rust will
automatically take care of many type conversions needed to build your Google
Maps requests.

* 3.5.1: 2024-05-11: Added an `Other` variant to most enums. The will
future-proof the crate for when Google Maps adds additional variants.
Previously, [serde](https://crates.io/crates/serde) would return an error when
* 2024-05-11: Added an `Other` variant to most enums. The will future-proof the
crate for when Google Maps adds additional variants. Previously,
[serde](https://crates.io/crates/serde) would return an error when
encountering unknown variants.

# 3.5.0

* 3.5.0: 2024-05-03: Improved ergonomics surrounding `Location` and `Waypoint`
types. New functions: `from_address`, `from_place_id`, `try_from_f32` and
* 2024-05-03: Improved ergonomics surrounding `Location` and `Waypoint` types.
New functions: `from_address`, `from_place_id`, `try_from_f32` and
`try_from_f64`.

* 3.5.0: 2024-05-03: `reqwest-maybe-middleware` was forked and integrated into
* 2024-05-03: `reqwest-maybe-middleware` was forked and integrated into
`google_maps` for now, until the crate can be updated. maybe-middleware has
also been properly feature-gated and is turned-off by default.

* 3.5.0: 2024-03-10: Addressed deprecated functions in the new `chrono` version
* 2024-03-10: Addressed deprecated functions in the new `chrono` version
`0.4.37`.

* 3.5.0: 2024-03-10: The ol' `cargo clippy --fix`
* 2024-03-10: The ol' `cargo clippy --fix`

* 3.5.0: 2024-03-03: Fixes for certain feature gate combinations.
* 2024-03-03: Fixes for certain feature gate combinations.

* 3.5.0: 2024-02-28: Improved string-passing ergonomics.
* 2024-02-28: Improved string-passing ergonomics.

* 3.5.0: 2024-02-22: ⚠ **Breaking change**: Replaced all instances of
`Option<Vec<_>>` with a `Vec<_>`.
* 2024-02-22: ⚠ **Breaking change**: Replaced all instances of `Option<Vec<_>>`
with a `Vec<_>`.

The `Option<Vec<_>>` was originally employed to get `serde` to
deserialize Google Maps data without any extra options. However, working
Expand Down
22 changes: 11 additions & 11 deletions src/client/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl GoogleMapsClient {
pub fn directions(
&self,
origin: impl Into<Location>,
destination: impl Into<Location>,
destination: impl Into<Location>
) -> crate::directions::request::Request {
crate::directions::request::Request::new(self, origin.into(), destination.into())
} // fn
Expand Down Expand Up @@ -183,7 +183,7 @@ impl GoogleMapsClient {
pub fn distance_matrix<C, W>(
&self,
origins: C,
destinations: C,
destinations: C
) -> crate::distance_matrix::request::Request
where
C: IntoIterator<Item = W>,
Expand Down Expand Up @@ -258,7 +258,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn reverse_geocoding(
&self,
location: impl Into<LatLng>,
location: impl Into<LatLng>
) -> crate::geocoding::reverse::ReverseRequest {
crate::geocoding::reverse::ReverseRequest::new(self, location.into())
} // fn
Expand Down Expand Up @@ -299,7 +299,7 @@ impl GoogleMapsClient {
pub fn time_zone(
&self,
location: impl Into<LatLng>,
timestamp: impl Into<DateTime<Utc>>,
timestamp: impl Into<DateTime<Utc>>
) -> crate::time_zone::request::Request {
crate::time_zone::request::Request::new(self, location.into(), timestamp.into())
} // fn
Expand All @@ -320,7 +320,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn place_autocomplete(
&self,
input: impl Into<String>,
input: impl Into<String>
) -> crate::places::place_autocomplete::request::Request {
crate::places::place_autocomplete::request::Request::new(self, input)
} // fn
Expand Down Expand Up @@ -360,7 +360,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn query_autocomplete(
&self,
input: impl Into<String>,
input: impl Into<String>
) -> crate::places::query_autocomplete::request::Request {
crate::places::query_autocomplete::request::Request::new(self, input)
} // fn
Expand Down Expand Up @@ -454,7 +454,7 @@ impl GoogleMapsClient {
pub fn text_search(
&self,
query: impl Into<String>,
radius: impl Into<u32>,
radius: impl Into<u32>
) -> crate::places::place_search::text_search::request::Request {
crate::places::place_search::text_search::request::Request::new(self, query, radius.into())
} // fn
Expand Down Expand Up @@ -511,7 +511,7 @@ impl GoogleMapsClient {
pub fn nearby_search(
&self,
location: impl Into<LatLng>,
radius: impl Into<u32>,
radius: impl Into<u32>
) -> crate::places::place_search::nearby_search::request::Request {
crate::places::place_search::nearby_search::request::Request::new(
self,
Expand Down Expand Up @@ -554,7 +554,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn place_details(
&self,
place_id: impl Into<String>,
place_id: impl Into<String>
) -> crate::places::place_details::request::Request {
crate::places::place_details::request::Request::new(
self,
Expand Down Expand Up @@ -614,7 +614,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn snap_to_roads<C, L>(
&self,
path: C,
path: C
) -> crate::roads::snap_to_roads::request::Request
where
C: IntoIterator<Item = L>,
Expand Down Expand Up @@ -664,7 +664,7 @@ impl GoogleMapsClient {
#[must_use]
pub fn nearest_roads<C, L>(
&self,
points: C,
points: C
) -> crate::roads::snap_to_roads::request::Request
where
C: IntoIterator<Item = L>,
Expand Down
4 changes: 2 additions & 2 deletions src/client/with_reqwest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl GoogleMapsClient {
#[cfg(all(feature = "enable-reqwest", feature = "enable-reqwest-middleware"))]
pub fn with_reqwest_middleware_client(
&mut self,
reqwest_client: reqwest_middleware::ClientWithMiddleware,
reqwest_client: reqwest_middleware::ClientWithMiddleware
) -> &mut Self {
self.reqwest_client = crate::reqwest_maybe_middleware::Client::Middleware(reqwest_client);
self
Expand All @@ -53,7 +53,7 @@ impl GoogleMapsClient {
#[cfg(all(feature = "enable-reqwest", feature = "enable-reqwest-middleware"))]
pub fn with_reqwest(
&mut self,
reqwest_client: crate::reqwest_maybe_middleware::Client,
reqwest_client: crate::reqwest_maybe_middleware::Client
) -> &mut Self {
self.reqwest_client = reqwest_client;
self
Expand Down
2 changes: 1 addition & 1 deletion src/directions/request/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> Request<'a> {
pub const fn new(
client: &'a GoogleMapsClient,
origin: Location,
destination: Location,
destination: Location
) -> Self {
Request {
// Required parameters:
Expand Down
7 changes: 5 additions & 2 deletions src/directions/request/with_alternatives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ impl<'a> Request<'a> {
/// .with_alternatives(true)
/// ```
pub fn with_alternatives(&'a mut self, alternatives: bool) -> &'a mut Self {
self.alternatives = Some(alternatives);
pub fn with_alternatives(
&'a mut self,
alternatives: impl Into<bool>
) -> &'a mut Self {
self.alternatives = Some(alternatives.into());
self
} // fn
} // impl
5 changes: 2 additions & 3 deletions src/directions/request/with_arrival_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ impl<'a> Request<'a> {
pub fn with_arrival_time(
&'a mut self,
arrival_time: impl Into<NaiveDateTime>,
arrival_time: impl Into<NaiveDateTime>
) -> &'a mut Self {
let arrival_time: NaiveDateTime = arrival_time.into();
self.arrival_time = Some(arrival_time);
self.arrival_time = Some(arrival_time.into());
self
} // fn
} // impl
7 changes: 5 additions & 2 deletions src/directions/request/with_departure_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ impl<'a> Request<'a> {
/// ))
/// ```
pub fn with_departure_time(&'a mut self, departure_time: DepartureTime) -> &'a mut Self {
self.departure_time = Some(departure_time);
pub fn with_departure_time(
&'a mut self,
departure_time: impl Into<DepartureTime>
) -> &'a mut Self {
self.departure_time = Some(departure_time.into());
self
} // fn
} // impl
7 changes: 5 additions & 2 deletions src/directions/request/with_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ impl<'a> Request<'a> {
/// .with_language(Language::French)
/// ```
pub fn with_language(&'a mut self, language: Language) -> &'a mut Self {
self.language = Some(language);
pub fn with_language(
&'a mut self,
language: impl Into<Language>
) -> &'a mut Self {
self.language = Some(language.into());
self
} // fn
} // impl
7 changes: 5 additions & 2 deletions src/directions/request/with_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ impl<'a> Request<'a> {
/// .with_region(Region::Canada)
/// ```
pub fn with_region(&'a mut self, region: Region) -> &'a mut Self {
self.region = Some(region);
pub fn with_region(
&'a mut self,
region: impl Into<Region>
) -> &'a mut Self {
self.region = Some(region.into());
self
} // fn
} // impl
9 changes: 6 additions & 3 deletions src/directions/request/with_restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ impl<'a> Request<'a> {
/// .with_restriction(Avoid::Ferries)
/// ```
pub fn with_restriction(&'a mut self, restriction: Avoid) -> &'a mut Self {
pub fn with_restriction(
&'a mut self,
restriction: impl Into<Avoid>
) -> &'a mut Self {
// Add restriction to Request struct.
self.restrictions = vec![restriction];
self.restrictions = vec![restriction.into()];
// Return modified Request struct to caller.
self
} // fn
Expand Down Expand Up @@ -87,7 +90,7 @@ impl<'a> Request<'a> {
pub fn with_restrictions<C, A>(
&'a mut self,
restrictions: C,
restrictions: C
) -> &'a mut Self
where
C: IntoIterator<Item = A>,
Expand Down
7 changes: 5 additions & 2 deletions src/directions/request/with_traffic_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ impl<'a> Request<'a> {
/// .with_traffic_model(TrafficModel::Pessimistic)
/// ```
pub fn with_traffic_model(&'a mut self, traffic_model: TrafficModel) -> &'a mut Self {
self.traffic_model = Some(traffic_model);
pub fn with_traffic_model(
&'a mut self,
traffic_model: impl Into<TrafficModel>
) -> &'a mut Self {
self.traffic_model = Some(traffic_model.into());
self
} // fn
} // impl
9 changes: 6 additions & 3 deletions src/directions/request/with_transit_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ impl<'a> Request<'a> {
/// ])
/// ```
pub fn with_transit_mode(&'a mut self, transit_mode: TransitMode) -> &'a mut Self {
pub fn with_transit_mode(
&'a mut self,
transit_mode: impl Into<TransitMode>
) -> &'a mut Self {
// Add restiction to Request struct.
self.transit_modes = vec![transit_mode];
self.transit_modes = vec![transit_mode.into()];
// Return modified Request struct to caller.
self
} // fn
Expand Down Expand Up @@ -78,7 +81,7 @@ impl<'a> Request<'a> {
pub fn with_transit_modes<C, T>(
&'a mut self,
transit_modes: C,
transit_modes: C
) -> &'a mut Self
where
C: IntoIterator<Item = T>,
Expand Down
4 changes: 2 additions & 2 deletions src/directions/request/with_transit_route_preference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ impl<'a> Request<'a> {
pub fn with_transit_route_preference(
&'a mut self,
transit_route_preference: TransitRoutePreference,
transit_route_preference: impl Into<TransitRoutePreference>
) -> &'a mut Self {
self.transit_route_preference = Some(transit_route_preference);
self.transit_route_preference = Some(transit_route_preference.into());
self
} // fn
} // impl
7 changes: 5 additions & 2 deletions src/directions/request/with_travel_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ impl<'a> Request<'a> {
/// .with_travel_mode(TravelMode::Transit)
/// ```
pub fn with_travel_mode(&'a mut self, travel_mode: TravelMode) -> &'a mut Self {
self.travel_mode = Some(travel_mode);
pub fn with_travel_mode(
&'a mut self,
travel_mode: impl Into<TravelMode>
) -> &'a mut Self {
self.travel_mode = Some(travel_mode.into());
self
} // fn
} // impl
7 changes: 5 additions & 2 deletions src/directions/request/with_unit_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ impl<'a> Request<'a> {
/// .with_unit_system(UnitSystem::Metric)
/// ```
pub fn with_unit_system(&'a mut self, unit_system: UnitSystem) -> &mut Self {
self.unit_system = Some(unit_system);
pub fn with_unit_system(
&'a mut self,
unit_system: impl Into<UnitSystem>
) -> &mut Self {
self.unit_system = Some(unit_system.into());
self
} // fn
} // impl
Loading

0 comments on commit f60f93e

Please sign in to comment.