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
/// A Haystack Coord, representing a geographical
/// coordinate.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Coord {
    lat: f64,
    lng: f64,
}

impl Coord {
    /// Create a new `Coord`.
    pub fn new(lat: f64, lng: f64) -> Self {
        Self { lat, lng }
    }

    /// Return the latitude component of this `Coord`.
    pub fn lat(&self) -> f64 {
        self.lat
    }

    /// Return the longitude component of this `Coord`.
    pub fn lng(&self) -> f64 {
        self.lng
    }
}

impl std::fmt::Display for Coord {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}, {}", self.lat(), self.lng())
    }
}