From 2a0f92a41172f0607a635b90a9200dfe3b586c51 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 31 May 2014 10:11:18 -0700 Subject: [PATCH] Update for cmp changes --- src/error.rs | 2 +- src/lib.rs | 2 +- src/test.rs | 2 +- src/types/array.rs | 4 ++-- src/types/mod.rs | 2 +- src/types/range.rs | 39 +++++++++++++++++++++++++++------------ 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/error.rs b/src/error.rs index 9439a3c0..3b5f358d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,7 +13,7 @@ use types::PostgresType; macro_rules! make_errors( ($($code:expr => $error:ident),+) => ( /// SQLSTATE error codes - #[deriving(Eq, Clone)] + #[deriving(PartialEq, TotalEq, Clone)] #[allow(missing_doc)] pub enum PostgresSqlState { $($error,)+ diff --git a/src/lib.rs b/src/lib.rs index da0083d0..da4e93b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1240,7 +1240,7 @@ impl<'conn> PostgresStatement<'conn> { } /// Information about a column of the result of a query. -#[deriving(Eq)] +#[deriving(PartialEq, TotalEq)] pub struct ResultDescription { /// The name of the column pub name: String, diff --git a/src/test.rs b/src/test.rs index 59c82ff9..6dacd35f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -421,7 +421,7 @@ fn test_execute_counts() { assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", []))); } -fn test_type(sql_type: &str, checks: &[(T, S)]) { +fn test_type(sql_type: &str, checks: &[(T, S)]) { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); for &(ref val, ref repr) in checks.iter() { let stmt = or_fail!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type).as_slice())); diff --git a/src/types/array.rs b/src/types/array.rs index 48bb2fa5..26049729 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -4,7 +4,7 @@ use std::mem; use std::slice; /// Information about a dimension of an array -#[deriving(Eq, Clone, Show)] +#[deriving(PartialEq, TotalEq, Clone, Show)] pub struct DimensionInfo { /// The size of the dimension pub len: uint, @@ -70,7 +70,7 @@ trait InternalMutableArray: MutableArray { } /// A multi-dimensional array -#[deriving(Eq, Clone)] +#[deriving(PartialEq, TotalEq, Clone)] pub struct ArrayBase { info: Vec, data: Vec, diff --git a/src/types/mod.rs b/src/types/mod.rs index 5b1a92f7..90d59aed 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -77,7 +77,7 @@ static RANGE_EMPTY: i8 = 0b0000_0001; macro_rules! make_postgres_type( ($(#[$doc:meta] $oid:ident => $variant:ident $(member $member:ident)*),+) => ( /// A Postgres type - #[deriving(Eq, Clone, Show)] + #[deriving(PartialEq, TotalEq, Clone, Show)] pub enum PostgresType { $( #[$doc] diff --git a/src/types/range.rs b/src/types/range.rs index a45125a3..084b7041 100644 --- a/src/types/range.rs +++ b/src/types/range.rs @@ -125,7 +125,7 @@ impl Normalizable for Timespec { } } -#[deriving(Eq)] +#[deriving(PartialEq, TotalEq)] enum BoundSide { Upper, Lower @@ -156,7 +156,7 @@ impl BoundSided for LowerBound { } /// The type of a range bound -#[deriving(Eq,Clone)] +#[deriving(PartialEq, TotalEq, Clone)] pub enum BoundType { /// The bound includes its value Inclusive, @@ -201,13 +201,15 @@ impl fmt::Show for RangeBound { } } -impl Eq for RangeBound { +impl PartialEq for RangeBound { fn eq(&self, other: &RangeBound) -> bool { self.value == other.value && self.type_ == other.type_ } } -impl Ord for RangeBound { +impl TotalEq for RangeBound {} + +impl PartialOrd for RangeBound { fn lt(&self, other: &RangeBound) -> bool { match (BoundSided::side(None::), self.type_, other.type_) { (Upper, Exclusive, Inclusive) @@ -217,7 +219,18 @@ impl Ord for RangeBound { } } -impl RangeBound { +impl TotalOrd for RangeBound { + fn cmp(&self, other: &RangeBound) -> Ordering { + match (BoundSided::side(None::), self.type_, other.type_, + self.value.cmp(&other.value)) { + (Upper, Exclusive, Inclusive, Equal) => Less, + (Lower, Inclusive, Exclusive, Equal) => Greater, + (_, _, _, ord) => ord, + } + } +} + +impl RangeBound { /// Constructs a new range bound pub fn new(value: T, type_: BoundType) -> RangeBound { RangeBound { value: value, type_: type_ } @@ -236,14 +249,16 @@ impl RangeBound { struct OptBound<'a, S, T>(Option<&'a RangeBound>); -impl<'a, S: BoundSided, T: Eq> Eq for OptBound<'a, S, T> { +impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> { fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool { let &OptBound(ref self_) = self; self_ == other } } -impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> { +impl<'a, S: BoundSided, T: TotalEq> TotalEq for OptBound<'a, S, T> {} + +impl<'a, S: BoundSided, T: PartialOrd> PartialOrd for OptBound<'a, S, T> { fn lt(&self, other: &OptBound<'a, S, T>) -> bool { match (*self, *other) { (OptBound(None), OptBound(None)) => false, @@ -255,12 +270,12 @@ impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> { } /// Represents a range of values. -#[deriving(Eq, Clone)] +#[deriving(PartialEq, TotalEq, Clone)] pub struct Range { inner: InnerRange, } -#[deriving(Eq,Clone)] +#[deriving(PartialEq, TotalEq, Clone)] enum InnerRange { Empty, Normal(Option>, @@ -286,7 +301,7 @@ impl fmt::Show for Range { } } -impl Range { +impl Range { /// Creates a new range. /// /// If a bound is `None`, the range is unbounded in that direction. @@ -366,7 +381,7 @@ impl Range { } } -fn order(a: T, b: T) -> (T, T) { +fn order(a: T, b: T) -> (T, T) { if a < b { (a, b) } else { @@ -374,7 +389,7 @@ fn order(a: T, b: T) -> (T, T) { } } -impl Range { +impl Range { /// Returns the intersection of this range with another pub fn intersect(&self, other: &Range) -> Range { if self.is_empty() || other.is_empty() {