1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::DecodeError;
use std::convert::TryFrom;
#[derive(Debug, Serialize, Clone)]
pub struct LatLong {
pub lat: f64,
pub long: f64,
}
impl TryFrom<String> for LatLong {
type Error = DecodeError;
fn try_from(
lat_long_str: String,
) -> std::result::Result<Self, <Self as TryFrom<String>>::Error> {
let mut iter = lat_long_str.splitn(2, ",");
Ok(LatLong {
lat: iter
.next()
.ok_or(DecodeError::LatMissing)?
.parse()
.or(Err(DecodeError::NumberParseError))?,
long: iter
.next()
.ok_or(DecodeError::LongMissing)?
.parse()
.or(Err(DecodeError::NumberParseError))?,
})
}
}