@@ -125,7 +125,7 @@ impl Normalizable for Timespec {
125125 }
126126}
127127
128- #[ deriving( Eq ) ]
128+ #[ deriving( PartialEq , TotalEq ) ]
129129enum 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 ) ]
160160pub 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
237250struct 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 ) ]
259274pub struct Range < T > {
260275 inner : InnerRange < T > ,
261276}
262277
263- #[ deriving( Eq , Clone ) ]
278+ #[ deriving( PartialEq , TotalEq , Clone ) ]
264279enum 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