From d0ac326944e6a9df3322533468b61c0d3559fd4e Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 6 Mar 2020 12:26:15 -0500 Subject: [PATCH] Add negation operator for Sign --- src/num.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/num.rs b/src/num.rs index dac4372..25a0450 100644 --- a/src/num.rs +++ b/src/num.rs @@ -7,7 +7,7 @@ use core::convert::TryFrom; use core::fmt::Debug; use core::ops::{ Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, - Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign, + Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign, }; /// Represents the sign of a rational number @@ -27,8 +27,16 @@ impl Default for Sign { } } +impl Neg for Sign { + type Output = Self; + + fn neg(self) -> Self::Output { + !self + } +} + impl Not for Sign { - type Output = Sign; + type Output = Self; fn not(self) -> Self::Output { match self {