Skip to content

Commit 2a0f92a

Browse files
committed
Update for cmp changes
1 parent e6b45ed commit 2a0f92a

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use types::PostgresType;
1313
macro_rules! make_errors(
1414
($($code:expr => $error:ident),+) => (
1515
/// SQLSTATE error codes
16-
#[deriving(Eq, Clone)]
16+
#[deriving(PartialEq, TotalEq, Clone)]
1717
#[allow(missing_doc)]
1818
pub enum PostgresSqlState {
1919
$($error,)+

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ impl<'conn> PostgresStatement<'conn> {
12401240
}
12411241

12421242
/// Information about a column of the result of a query.
1243-
#[deriving(Eq)]
1243+
#[deriving(PartialEq, TotalEq)]
12441244
pub struct ResultDescription {
12451245
/// The name of the column
12461246
pub name: String,

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn test_execute_counts() {
421421
assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", [])));
422422
}
423423

424-
fn test_type<T: Eq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
424+
fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
425425
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
426426
for &(ref val, ref repr) in checks.iter() {
427427
let stmt = or_fail!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type).as_slice()));

src/types/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44
use std::slice;
55

66
/// Information about a dimension of an array
7-
#[deriving(Eq, Clone, Show)]
7+
#[deriving(PartialEq, TotalEq, Clone, Show)]
88
pub struct DimensionInfo {
99
/// The size of the dimension
1010
pub len: uint,
@@ -70,7 +70,7 @@ trait InternalMutableArray<T>: MutableArray<T> {
7070
}
7171

7272
/// A multi-dimensional array
73-
#[deriving(Eq, Clone)]
73+
#[deriving(PartialEq, TotalEq, Clone)]
7474
pub struct ArrayBase<T> {
7575
info: Vec<DimensionInfo>,
7676
data: Vec<T>,

src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static RANGE_EMPTY: i8 = 0b0000_0001;
7777
macro_rules! make_postgres_type(
7878
($(#[$doc:meta] $oid:ident => $variant:ident $(member $member:ident)*),+) => (
7979
/// A Postgres type
80-
#[deriving(Eq, Clone, Show)]
80+
#[deriving(PartialEq, TotalEq, Clone, Show)]
8181
pub enum PostgresType {
8282
$(
8383
#[$doc]

src/types/range.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Normalizable for Timespec {
125125
}
126126
}
127127

128-
#[deriving(Eq)]
128+
#[deriving(PartialEq, TotalEq)]
129129
enum BoundSide {
130130
Upper,
131131
Lower
@@ -156,7 +156,7 @@ impl BoundSided for LowerBound {
156156
}
157157

158158
/// The type of a range bound
159-
#[deriving(Eq,Clone)]
159+
#[deriving(PartialEq, TotalEq, Clone)]
160160
pub enum BoundType {
161161
/// The bound includes its value
162162
Inclusive,
@@ -201,13 +201,15 @@ impl<S: BoundSided, T: fmt::Show> fmt::Show for RangeBound<S, T> {
201201
}
202202
}
203203

204-
impl<S: BoundSided, T: Eq> Eq for RangeBound<S, T> {
204+
impl<S: BoundSided, T: PartialEq> PartialEq for RangeBound<S, T> {
205205
fn eq(&self, other: &RangeBound<S, T>) -> bool {
206206
self.value == other.value && self.type_ == other.type_
207207
}
208208
}
209209

210-
impl<S: BoundSided, T: Ord> Ord for RangeBound<S, T> {
210+
impl<S: BoundSided, T: TotalEq> TotalEq for RangeBound<S, T> {}
211+
212+
impl<S: BoundSided, T: PartialOrd> PartialOrd for RangeBound<S, T> {
211213
fn lt(&self, other: &RangeBound<S, T>) -> bool {
212214
match (BoundSided::side(None::<S>), self.type_, other.type_) {
213215
(Upper, Exclusive, Inclusive)
@@ -217,7 +219,18 @@ impl<S: BoundSided, T: Ord> Ord for RangeBound<S, T> {
217219
}
218220
}
219221

220-
impl<S: BoundSided, T: Ord> RangeBound<S, T> {
222+
impl<S: BoundSided, T: TotalOrd> TotalOrd for RangeBound<S, T> {
223+
fn cmp(&self, other: &RangeBound<S, T>) -> Ordering {
224+
match (BoundSided::side(None::<S>), self.type_, other.type_,
225+
self.value.cmp(&other.value)) {
226+
(Upper, Exclusive, Inclusive, Equal) => Less,
227+
(Lower, Inclusive, Exclusive, Equal) => Greater,
228+
(_, _, _, ord) => ord,
229+
}
230+
}
231+
}
232+
233+
impl<S: BoundSided, T: PartialOrd> RangeBound<S, T> {
221234
/// Constructs a new range bound
222235
pub fn new(value: T, type_: BoundType) -> RangeBound<S, T> {
223236
RangeBound { value: value, type_: type_ }
@@ -236,14 +249,16 @@ impl<S: BoundSided, T: Ord> RangeBound<S, T> {
236249

237250
struct OptBound<'a, S, T>(Option<&'a RangeBound<S, T>>);
238251

239-
impl<'a, S: BoundSided, T: Eq> Eq for OptBound<'a, S, T> {
252+
impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> {
240253
fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {
241254
let &OptBound(ref self_) = self;
242255
self_ == other
243256
}
244257
}
245258

246-
impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> {
259+
impl<'a, S: BoundSided, T: TotalEq> TotalEq for OptBound<'a, S, T> {}
260+
261+
impl<'a, S: BoundSided, T: PartialOrd> PartialOrd for OptBound<'a, S, T> {
247262
fn lt(&self, other: &OptBound<'a, S, T>) -> bool {
248263
match (*self, *other) {
249264
(OptBound(None), OptBound(None)) => false,
@@ -255,12 +270,12 @@ impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> {
255270
}
256271

257272
/// Represents a range of values.
258-
#[deriving(Eq, Clone)]
273+
#[deriving(PartialEq, TotalEq, Clone)]
259274
pub struct Range<T> {
260275
inner: InnerRange<T>,
261276
}
262277

263-
#[deriving(Eq,Clone)]
278+
#[deriving(PartialEq, TotalEq, Clone)]
264279
enum InnerRange<T> {
265280
Empty,
266281
Normal(Option<RangeBound<LowerBound, T>>,
@@ -286,7 +301,7 @@ impl<T: fmt::Show> fmt::Show for Range<T> {
286301
}
287302
}
288303

289-
impl<T: Ord+Normalizable> Range<T> {
304+
impl<T: PartialOrd+Normalizable> Range<T> {
290305
/// Creates a new range.
291306
///
292307
/// If a bound is `None`, the range is unbounded in that direction.
@@ -366,15 +381,15 @@ impl<T: Ord+Normalizable> Range<T> {
366381
}
367382
}
368383

369-
fn order<T:Ord>(a: T, b: T) -> (T, T) {
384+
fn order<T:PartialOrd>(a: T, b: T) -> (T, T) {
370385
if a < b {
371386
(a, b)
372387
} else {
373388
(b, a)
374389
}
375390
}
376391

377-
impl<T: Ord+Normalizable+Clone> Range<T> {
392+
impl<T: PartialOrd+Normalizable+Clone> Range<T> {
378393
/// Returns the intersection of this range with another
379394
pub fn intersect(&self, other: &Range<T>) -> Range<T> {
380395
if self.is_empty() || other.is_empty() {

0 commit comments

Comments
 (0)