@@ -150,27 +150,25 @@ impl Normalizable for Timespec {
150150 }
151151}
152152
153- /// The possible sides of a bound
154- #[ derive( PartialEq , Eq , Clone , Copy ) ]
153+ /// The possible sides of a bound.
154+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
155155pub enum BoundSide {
156- /// An upper bound
156+ /// An upper bound.
157157 Upper ,
158- /// A lower bound
158+ /// A lower bound.
159159 Lower
160160}
161161
162- /// A trait implemented by phantom types indicating the type of the bound
162+ /// A trait implemented by phantom types indicating the type of the bound.
163163pub trait BoundSided {
164- /// Returns the bound side this type corresponds to
164+ /// Returns the bound side this type corresponds to.
165165 fn side ( ) -> BoundSide ;
166166}
167167
168168/// A tag type representing an upper bound
169- #[ allow( missing_copy_implementations) ]
170169pub enum UpperBound { }
171170
172171/// A tag type representing a lower bound
173- #[ allow( missing_copy_implementations) ]
174172pub enum LowerBound { }
175173
176174impl BoundSided for UpperBound {
@@ -185,22 +183,22 @@ impl BoundSided for LowerBound {
185183 }
186184}
187185
188- /// The type of a range bound
189- #[ derive( PartialEq , Eq , Clone , Copy ) ]
186+ /// The type of a range bound.
187+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
190188pub enum BoundType {
191- /// The bound includes its value
189+ /// The bound includes its value.
192190 Inclusive ,
193- /// The bound excludes its value
191+ /// The bound excludes its value.
194192 Exclusive
195193}
196194
197195/// Represents a one-sided bound.
198196///
199197/// The side is determined by the `S` phantom parameter.
200198pub struct RangeBound < S : BoundSided , T > {
201- /// The value of the bound
199+ /// The value of the bound.
202200 pub value : T ,
203- /// The type of the bound
201+ /// The type of the bound.
204202 pub type_ : BoundType ,
205203 _m : PhantomData < * mut S > ,
206204}
@@ -218,15 +216,24 @@ impl<S, T> Clone for RangeBound<S, T> where S: BoundSided, T: Clone {
218216}
219217
220218impl < S , T > fmt:: Debug for RangeBound < S , T > where S : BoundSided , T : fmt:: Debug {
219+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
220+ fmt. debug_struct ( "RangeBound" )
221+ . field ( "value" , & self . value )
222+ . field ( "type_" , & self . type_ )
223+ . finish ( )
224+ }
225+ }
226+
227+ impl < S , T > fmt:: Display for RangeBound < S , T > where S : BoundSided , T : fmt:: Display {
221228 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
222229 let ( lower, upper) = match self . type_ {
223230 Inclusive => ( '[' , ']' ) ,
224231 Exclusive => ( '(' , ')' ) ,
225232 } ;
226233
227234 match <S as BoundSided >:: side ( ) {
228- Lower => write ! ( fmt, "{}{:? }" , lower, self . value) ,
229- Upper => write ! ( fmt, "{:? }{}" , self . value, upper) ,
235+ Lower => write ! ( fmt, "{}{}" , lower, self . value) ,
236+ Upper => write ! ( fmt, "{}{}" , self . value, upper) ,
230237 }
231238 }
232239}
@@ -290,7 +297,7 @@ impl<S, T> RangeBound<S, T> where S: BoundSided, T: PartialOrd {
290297 }
291298}
292299
293- struct OptBound < ' a , S : ' a + BoundSided , T : ' a > ( Option < & ' a RangeBound < S , T > > ) ;
300+ struct OptBound < ' a , S : ' a + BoundSided , T : ' a > ( Option < & ' a RangeBound < S , T > > ) ;
294301
295302impl < ' a , S , T > PartialEq for OptBound < ' a , S , T > where S : BoundSided , T : PartialEq {
296303 fn eq ( & self , & OptBound ( ref other) : & OptBound < ' a , S , T > ) -> bool {
@@ -318,38 +325,38 @@ impl<'a, S, T> PartialOrd for OptBound<'a, S, T> where S: BoundSided, T: Partial
318325}
319326
320327/// Represents a range of values.
321- #[ derive( PartialEq , Eq , Clone , Copy ) ]
328+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
322329pub struct Range < T > {
323330 inner : InnerRange < T > ,
324331}
325332
326- #[ derive( PartialEq , Eq , Clone , Copy ) ]
333+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
327334enum InnerRange < T > {
328335 Empty ,
329336 Normal ( Option < RangeBound < LowerBound , T > > ,
330337 Option < RangeBound < UpperBound , T > > )
331338}
332339
333- impl < T > fmt:: Debug for Range < T > where T : fmt:: Debug {
340+ impl < T > fmt:: Display for Range < T > where T : fmt:: Display {
334341 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
335342 match self . inner {
336343 Empty => write ! ( fmt, "empty" ) ,
337344 Normal ( ref lower, ref upper) => {
338345 match * lower {
339- Some ( ref bound) => try!( write ! ( fmt, "{:? }" , bound) ) ,
346+ Some ( ref bound) => try!( write ! ( fmt, "{}" , bound) ) ,
340347 None => try!( write ! ( fmt, "(" ) ) ,
341348 }
342349 try!( write ! ( fmt, "," ) ) ;
343350 match * upper {
344- Some ( ref bound) => write ! ( fmt, "{:? }" , bound) ,
351+ Some ( ref bound) => write ! ( fmt, "{}" , bound) ,
345352 None => write ! ( fmt, ")" ) ,
346353 }
347354 }
348355 }
349356 }
350357}
351358
352- impl < T > Range < T > where T : PartialOrd + Normalizable {
359+ impl < T > Range < T > where T : PartialOrd + Normalizable {
353360 /// Creates a new range.
354361 ///
355362 /// If a bound is `None`, the range is unbounded in that direction.
@@ -435,7 +442,7 @@ fn order<T>(a: T, b: T) -> (T, T) where T: PartialOrd {
435442}
436443
437444impl < T > Range < T > where T : PartialOrd +Normalizable +Clone {
438- /// Returns the intersection of this range with another
445+ /// Returns the intersection of this range with another.
439446 pub fn intersect ( & self , other : & Range < T > ) -> Range < T > {
440447 if self . is_empty ( ) || other. is_empty ( ) {
441448 return Range :: empty ( ) ;
@@ -449,7 +456,7 @@ impl<T> Range<T> where T: PartialOrd+Normalizable+Clone {
449456 Range :: new ( lower. map ( |v| v. clone ( ) ) , upper. map ( |v| v. clone ( ) ) )
450457 }
451458
452- /// Returns the union of this range with another if it is contiguous
459+ /// Returns the union of this range with another if it is contiguous.
453460 pub fn union ( & self , other : & Range < T > ) -> Option < Range < T > > {
454461 if self . is_empty ( ) {
455462 return Some ( other. clone ( ) ) ;
0 commit comments