use crate::elevation::request::locations::Locations;
use crate::types::LatLng;
use geo_types::geometry::{Line, LineString};
impl TryFrom<&Line> for Locations {
type Error = crate::error::Error;
fn try_from(line: &Line) -> Result<Self, Self::Error> {
let lat_lngs: Vec<LatLng> =
vec![LatLng::try_from(&line.start)?, LatLng::try_from(&line.end)?];
Ok(Self::LatLngs(lat_lngs))
} }
impl TryFrom<Line> for Locations {
type Error = crate::error::Error;
fn try_from(line: Line) -> Result<Self, Self::Error> {
(&line).try_into()
} }
impl TryFrom<&LineString> for Locations {
type Error = crate::error::Error;
fn try_from(line_string: &LineString) -> Result<Self, Self::Error> {
let lat_lngs: Vec<LatLng> = line_string
.coords()
.map(LatLng::try_from)
.collect::<Result<Vec<LatLng>, _>>()?;
Ok(Self::LatLngs(lat_lngs))
} }
impl TryFrom<LineString> for Locations {
type Error = crate::error::Error;
fn try_from(line_string: LineString) -> Result<Self, Self::Error> {
(&line_string).try_into()
} }