#[cfg(feature = "geo")]
mod geo;
use crate::types::LatLng;
use crate::GoogleMapsError;
use rust_decimal::Decimal;
#[cfg(not(feature = "geo"))]
#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
)]
pub enum Waypoint {
Address(String),
LatLng(LatLng),
PlaceId(String),
Polyline(String),
}
#[cfg(not(feature = "geo"))]
impl std::convert::From<&Waypoint> for String {
fn from(waypoint: &Waypoint) -> Self {
match waypoint {
Waypoint::Address(address) => address.clone(),
Waypoint::LatLng(latlng) => Self::from(latlng),
Waypoint::PlaceId(place_id) => format!("place_id:{place_id}"),
Waypoint::Polyline(polyline) => format!("enc:{polyline}:"),
} } }
impl std::convert::From<&Self> for Waypoint {
fn from(waypoint: &Self) -> Self {
waypoint.clone()
} }
#[cfg(feature = "geo")]
#[derive(Clone, Debug, PartialEq)]
pub enum Waypoint {
Address(String),
LatLng(LatLng),
PlaceId(String),
Polyline(String),
Coord(geo_types::geometry::Coord),
Point(geo_types::geometry::Point),
}
#[cfg(feature = "geo")]
impl std::convert::From<&Waypoint> for String {
fn from(waypoint: &Waypoint) -> Self {
match waypoint {
Waypoint::Address(address) => address.clone(),
Waypoint::LatLng(latlng) => Self::from(latlng),
Waypoint::PlaceId(place_id) => format!("place_id:{place_id}"),
Waypoint::Polyline(polyline) => format!("enc:{polyline}:"),
Waypoint::Coord(coordinate) => format!(
"{latitude},{longitude}",
latitude = coordinate.y,
longitude = coordinate.x
),
Waypoint::Point(point) => format!(
"{latitude},{longitude}",
latitude = point.y(),
longitude = point.x()
),
} } }
impl Waypoint {
pub fn from_address(address: impl Into<String>) -> Self {
Self::Address(address.into())
} }
impl Waypoint {
pub fn from_place_id(place_id: impl Into<String>) -> Self {
Self::PlaceId(place_id.into())
} }
impl Waypoint {
pub fn from_polyline(polyline: impl Into<String>) -> Self {
Self::Polyline(polyline.into())
} }
impl Waypoint {
pub fn try_from_dec(latitude: Decimal, longitude: Decimal) -> Result<Self, GoogleMapsError> {
let latlng = LatLng::try_from_dec(latitude, longitude)?;
Ok(Self::LatLng(latlng))
} }
impl Waypoint {
pub fn try_from_f32(latitude: f32, longitude: f32) -> Result<Self, GoogleMapsError> {
let latlng = LatLng::try_from_f32(latitude, longitude)?;
Ok(Self::LatLng(latlng))
} }
impl Waypoint {
pub fn try_from_f64(latitude: f64, longitude: f64) -> Result<Self, GoogleMapsError> {
let latlng = LatLng::try_from_f64(latitude, longitude)?;
Ok(Self::LatLng(latlng))
} }
impl From<LatLng> for Waypoint {
fn from(latlng: LatLng) -> Self {
Self::LatLng(latlng)
} }
impl From<&LatLng> for Waypoint {
fn from(latlng: &LatLng) -> Self {
Self::LatLng(*latlng)
} }