@@ -10,16 +10,14 @@ pub(crate) trait RangeExt<T> {
1010
1111pub ( crate ) struct DisplayRange < T > ( T ) ;
1212
13- impl Display for DisplayRange < & Range < usize > > {
13+ impl Display for DisplayRange < & RangeInclusive < usize > > {
1414 fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
15- if self . 0 . start == self . 0 . end {
16- write ! ( f, "0" ) ?;
17- } else if self . 0 . start == self . 0 . end - 1 {
18- write ! ( f, "{}" , self . 0 . start) ?;
19- } else if self . 0 . end == usize:: MAX {
20- write ! ( f, "{} or more" , self . 0 . start) ?;
15+ if self . 0 . start ( ) == self . 0 . end ( ) {
16+ write ! ( f, "{}" , self . 0 . start( ) ) ?;
17+ } else if * self . 0 . end ( ) == usize:: MAX {
18+ write ! ( f, "{} or more" , self . 0 . start( ) ) ?;
2119 } else {
22- write ! ( f, "{} to {}" , self . 0 . start, self . 0 . end - 1 ) ?;
20+ write ! ( f, "{} to {}" , self . 0 . start( ) , self . 0 . end( ) ) ?;
2321 }
2422 Ok ( ( ) )
2523 }
@@ -76,10 +74,10 @@ mod tests {
7674 assert ! ( !( 1 ..1 ) . contains( & 1 ) ) ;
7775 assert ! ( ( 1 ..1 ) . is_empty( ) ) ;
7876 assert ! ( ( 5 ..5 ) . is_empty( ) ) ;
79- assert_eq ! ( ( 1 .. 1 ) . display( ) . to_string( ) , "0" ) ;
80- assert_eq ! ( ( 1 ..2 ) . display( ) . to_string( ) , "1" ) ;
81- assert_eq ! ( ( 5 ..6 ) . display( ) . to_string( ) , "5" ) ;
82- assert_eq ! ( ( 5 ..10 ) . display( ) . to_string( ) , "5 to 9" ) ;
83- assert_eq ! ( ( 1 ..usize :: MAX ) . display( ) . to_string( ) , "1 or more" ) ;
77+ assert_eq ! ( ( 0 ..= 0 ) . display( ) . to_string( ) , "0" ) ;
78+ assert_eq ! ( ( 1 ..= 1 ) . display( ) . to_string( ) , "1" ) ;
79+ assert_eq ! ( ( 5 ..= 5 ) . display( ) . to_string( ) , "5" ) ;
80+ assert_eq ! ( ( 5 ..= 9 ) . display( ) . to_string( ) , "5 to 9" ) ;
81+ assert_eq ! ( ( 1 ..= usize :: MAX ) . display( ) . to_string( ) , "1 or more" ) ;
8482 }
8583}
0 commit comments