Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Oct 20, 2020
1 parent 366f3dd commit 2f7ead0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/coord/lat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ impl<A: Angle> AngleAndDirection<A> for Latitude<A> {
}
}

impl<A: Angle> ParsedCoordinate<A> for Latitude<A>
impl<A> ParsedCoordinate<A> for Latitude<A>
where
A: FromStr<Err = <A as Angle>::ParseErr>,
A: Angle + FromStr<Err = <A as Angle>::ParseErr>,
A::ParseErr: From<A::NumErr>,
{
fn with_angle_only(angle: A) -> Option<Self> {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<A: Angle> TryFrom<f64> for Latitude<A> {
type Error = A::NumErr;

fn try_from(value: f64) -> Result<Self, Self::Error> {
let (value, is_north) = value.unsigned_abs();
let (value, is_north) = value.abs_and_sign();
let angle = value.try_into()?;
Self::with_angle_and_direction(angle, is_north.into())
}
Expand All @@ -162,7 +162,7 @@ where
fn try_from(value: (i16, u8, u8, u16)) -> Result<Self, Self::Error> {
let (deg, min, sec, milli) = value;

let (deg, sign) = deg.unsigned_abs();
let (deg, sign) = deg.abs_and_sign();
let angle = (deg, min, sec, milli).try_into()?;

Self::with_angle_and_direction(angle, sign.into())
Expand Down
6 changes: 3 additions & 3 deletions src/coord/lon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<A: Angle> AngleAndDirection<A> for Longitude<A> {
}
}

impl<A: Angle> ParsedCoordinate<A> for Longitude<A>
impl<A> ParsedCoordinate<A> for Longitude<A>
where
A: Angle + FromStr<Err = <A as Angle>::ParseErr>,
A::ParseErr: From<A::NumErr>,
Expand Down Expand Up @@ -197,7 +197,7 @@ impl<A: Angle> TryFrom<f64> for Longitude<A> {
type Error = A::NumErr;

fn try_from(value: f64) -> Result<Self, Self::Error> {
let (value, is_east) = value.unsigned_abs();
let (value, is_east) = value.abs_and_sign();
let angle = value.try_into()?;
Self::with_angle_and_direction(angle, is_east.into())
}
Expand All @@ -212,7 +212,7 @@ where
fn try_from(value: (i16, u8, u8, u16)) -> Result<Self, Self::Error> {
let (deg, min, sec, milli) = value;

let (deg, is_east) = deg.unsigned_abs();
let (deg, is_east) = deg.abs_and_sign();
let angle = (deg, min, sec, milli).try_into()?;

Self::with_angle_and_direction(angle, is_east.into())
Expand Down
24 changes: 12 additions & 12 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub trait ToUnsigned<U>: Default + Copy + PartialOrd + Neg<Output = Self> {
/// represent the source (signed) type as target (unsigned) type
fn as_type(self) -> U;

/// Converts to unsigned absolute value
fn unsigned_abs(self) -> (U, bool) {
/// Converts to unsigned absolute value, also preserving the 'is negative' flag
fn abs_and_sign(self) -> (U, bool) {
if self >= Self::default() {
(self.as_type(), true)
} else {
Expand All @@ -31,7 +31,7 @@ pub trait ToUnsigned<U>: Default + Copy + PartialOrd + Neg<Output = Self> {
}
}

macro_rules! impl_unsigned_abs {
macro_rules! impl_abs_and_sign {
($from: tt -> $to: ty) => {
impl ToUnsigned<$to> for $from {
fn as_type(self) -> $to {
Expand All @@ -49,11 +49,11 @@ macro_rules! impl_unsigned_abs {
};
}

impl_unsigned_abs!(i8 -> u8);
impl_unsigned_abs!(i16 -> u16);
impl_unsigned_abs!(i32 -> u32);
impl_unsigned_abs!(i64 -> u64);
impl_unsigned_abs!(f64);
impl_abs_and_sign!(i8 -> u8);
impl_abs_and_sign!(i16 -> u16);
impl_abs_and_sign!(i32 -> u32);
impl_abs_and_sign!(i64 -> u64);
impl_abs_and_sign!(f64);

/// Strip the given character from the beginning or the end
pub trait StripChar {
Expand Down Expand Up @@ -160,11 +160,11 @@ mod tests {

#[test]
fn unsigned() {
assert_eq!(7_i8.unsigned_abs(), (7_u8, true));
assert_eq!((-7_i8).unsigned_abs(), (7_u8, false));
assert_eq!(7_i8.abs_and_sign(), (7_u8, true));
assert_eq!((-7_i8).abs_and_sign(), (7_u8, false));

assert_eq!(1283_i16.unsigned_abs(), (1283_u16, true));
assert_eq!((-25_038_i16).unsigned_abs(), (25_038_u16, false));
assert_eq!(1283_i16.abs_and_sign(), (1283_u16, true));
assert_eq!((-25_038_i16).abs_and_sign(), (25_038_u16, false));
}

//noinspection SpellCheckingInspection
Expand Down

0 comments on commit 2f7ead0

Please sign in to comment.