Upgrade variables to 64 bit

This commit is contained in:
Matthias Beyer 2018-04-28 23:24:27 +02:00
parent f493b4b8c3
commit 93c3bb5862

View file

@ -34,14 +34,14 @@ pub trait FromValue : Sized {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct GPSValue {
pub degree: i32,
pub minutes: i32,
pub seconds: i32,
pub degree: i64,
pub minutes: i64,
pub seconds: i64,
}
impl GPSValue {
pub fn new(d: i32, m: i32, s: i32) -> GPSValue {
pub fn new(d: i64, m: i64, s: i64) -> GPSValue {
GPSValue {
degree: d,
minutes: m,
@ -49,15 +49,15 @@ impl GPSValue {
}
}
pub fn degree(&self) -> i32 {
pub fn degree(&self) -> i64 {
self.degree
}
pub fn minutes(&self) -> i32 {
pub fn minutes(&self) -> i64 {
self.minutes
}
pub fn seconds(&self) -> i32 {
pub fn seconds(&self) -> i64 {
self.seconds
}
@ -68,9 +68,9 @@ impl Into<Value> for GPSValue {
fn into(self) -> Value {
let mut map = BTreeMap::new();
let _ = map.insert("degree".to_owned(), Value::Integer(self.degree as i64));
let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes as i64));
let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds as i64));
let _ = map.insert("degree".to_owned(), Value::Integer(self.degree));
let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes));
let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds));
Value::Table(map)
}
@ -80,7 +80,7 @@ impl FromValue for GPSValue {
fn from_value(v: &Value) -> Result<Self> {
let int_to_appropriate_width = |v: &Value| {
v.as_integer()
.ok_or(GPSE::from_kind(GPSEK::HeaderTypeError)).and_then(i64_to_i32)
.ok_or(GPSE::from_kind(GPSEK::HeaderTypeError))
};
match *v {
@ -172,12 +172,4 @@ impl Display for Coordinates {
}
}
/// Helper to convert a i64 to i32 or return an error if this doesn't work.
fn i64_to_i32(i: i64) -> Result<i32> {
if i > (<i32>::max_value() as i64) {
Err(GPSE::from_kind(GPSEK::NumberConversionError))
} else {
Ok(i as i32)
}
}