From 10c3c2504076134dcd275e7d120d6a430879fea3 Mon Sep 17 00:00:00 2001 From: Dylan Bowker Date: Thu, 25 Jul 2024 13:00:50 -0600 Subject: [PATCH] feat: conversions for `LatLng` and `Waypoint`, `Location` --- CHANGELOG.md | 14 +++++++++++--- Cargo.toml | 2 +- src/directions/request/location/mod.rs | 18 ++++++++++++++++++ src/directions/request/waypoint/mod.rs | 18 ++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 532d036..c27a610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ * Release notes are available on [GitHub](https://github.com/leontoeides/google_maps/releases). -# 3.5.4 +# 3.5.5 -* 2024-06-15: This crate now instructs `serde` to not serialize empty fields. - This may potentially save a bit of disk space and bandwidth. +* 2024-07-25: Added additional conversion traits between `Location` & `Waypoint` + and `LatLng` for improved ergonomics. + +# 3.5.4 * 2024-07-25: Added support for getting `LatLng` structs from tuples `(43.68, 7.32)` @@ -15,6 +17,12 @@ * 2024-07-25: Dependency bumps +* 2024-07-19: Adjusts `reqwest` client's default timeouts for more reliable + operation. + +* 2024-06-15: This crate now instructs `serde` to not serialize empty fields. + This may potentially save a bit of disk space and bandwidth. + # 3.5.3 * 2024-06-09: Increased flexibility of interface by using more `impl Into` diff --git a/Cargo.toml b/Cargo.toml index 0f977f0..d08649a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "google_maps" -version = "3.5.4" +version = "3.5.5" authors = [ "Dylan Bowker " ] edition = "2021" categories = [ "api-bindings" ] diff --git a/src/directions/request/location/mod.rs b/src/directions/request/location/mod.rs index 7a40bb5..04c4023 100644 --- a/src/directions/request/location/mod.rs +++ b/src/directions/request/location/mod.rs @@ -215,3 +215,21 @@ impl Location { Ok(Self::LatLng(latlng)) } // fn } // impl + +// ----------------------------------------------------------------------------- + +impl From for Location { + /// Converts an owned `LatLng` coordinates type into a `Location` type. + fn from(latlng: LatLng) -> Self { + Self::LatLng(latlng) + } // fn +} // impl + +// ----------------------------------------------------------------------------- + +impl From<&LatLng> for Location { + /// Converts a borrowed `&LatLng` coordinates type into a `Location` type. + fn from(latlng: &LatLng) -> Self { + Self::LatLng(*latlng) + } // fn +} // impl diff --git a/src/directions/request/waypoint/mod.rs b/src/directions/request/waypoint/mod.rs index 534a3b2..7af3821 100644 --- a/src/directions/request/waypoint/mod.rs +++ b/src/directions/request/waypoint/mod.rs @@ -237,3 +237,21 @@ impl Waypoint { Ok(Self::LatLng(latlng)) } // fn } // impl + +// ----------------------------------------------------------------------------- + +impl From for Waypoint { + /// Converts an owned `LatLng` coordinates type into a `Waypoint` type. + fn from(latlng: LatLng) -> Self { + Self::LatLng(latlng) + } // fn +} // impl + +// ----------------------------------------------------------------------------- + +impl From<&LatLng> for Waypoint { + /// Converts a borrowed `&LatLng` coordinates type into a `Waypoint` type. + fn from(latlng: &LatLng) -> Self { + Self::LatLng(*latlng) + } // fn +} // impl