Impl Display for {GPSValue, Coordinates}

This commit is contained in:
Matthias Beyer 2017-09-21 17:23:46 +02:00
parent a34a9239a7
commit 0efffdbea3

View file

@ -18,6 +18,9 @@
//
use std::collections::BTreeMap;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use toml::Value;
@ -96,6 +99,12 @@ impl FromValue for GPSValue {
}
impl Display for GPSValue {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}° {}\" {}'", self.degree, self.minutes, self.seconds)
}
}
/// Data-transfer type for transfering longitude-latitude-pairs
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Coordinates {
@ -145,6 +154,12 @@ impl FromValue for Coordinates {
}
impl Display for Coordinates {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "longitude = {}\nlatitude = {}", self.longitude, self.latitude)
}
}
/// Helper to convert a i64 to i8 or return an error if this doesn't work.
fn i64_to_i8(i: i64) -> Result<i8> {
if i > (<i8>::max_value() as i64) {