@@ -65,6 +65,7 @@ use clone::Clone;
65
65
use iter:: { Step , Iterator , DoubleEndedIterator , ExactSizeIterator } ;
66
66
use marker:: Sized ;
67
67
use option:: Option :: { self , Some , None } ;
68
+ use fmt;
68
69
69
70
/// The `Drop` trait is used to run some code when a value goes out of scope. This
70
71
/// is sometimes called a 'destructor'.
@@ -847,13 +848,27 @@ pub trait IndexMut<Index: ?Sized> {
847
848
}
848
849
849
850
/// An unbounded range.
850
- #[ derive( Copy ) ]
851
+ #[ derive( Copy , PartialEq , Eq ) ]
851
852
#[ lang="full_range" ]
852
853
#[ unstable = "API still in development" ]
853
854
pub struct FullRange ;
854
855
856
+ #[ unstable = "API still in development" ]
857
+ impl fmt:: Show for FullRange {
858
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
859
+ fmt:: Show :: fmt ( ".." , fmt)
860
+ }
861
+ }
862
+
863
+ #[ unstable = "API still in development" ]
864
+ impl fmt:: String for FullRange {
865
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
866
+ fmt:: String :: fmt ( ".." , fmt)
867
+ }
868
+ }
869
+
855
870
/// A (half-open) range which is bounded at both ends.
856
- #[ derive( Copy ) ]
871
+ #[ derive( Copy , PartialEq , Eq ) ]
857
872
#[ lang="range" ]
858
873
#[ unstable = "API still in development" ]
859
874
pub struct Range < Idx > {
@@ -904,8 +919,29 @@ impl<Idx: Clone + Step> DoubleEndedIterator for Range<Idx> {
904
919
#[ unstable = "API still in development" ]
905
920
impl < Idx : Clone + Step > ExactSizeIterator for Range < Idx > { }
906
921
922
+ #[ unstable = "API still in development" ]
923
+ impl < Idx : fmt:: Show > fmt:: Show for Range < Idx > {
924
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
925
+ write ! ( fmt, "{:?}..{:?}" , self . start, self . end)
926
+ }
927
+ }
928
+ #[ cfg( stage0) ]
929
+ #[ unstable = "API still in development" ]
930
+ impl < Idx : fmt:: String + fmt:: Show > fmt:: String for Range < Idx > {
931
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
932
+ write ! ( fmt, "{}..{}" , self . start, self . end)
933
+ }
934
+ }
935
+ #[ cfg( not( stage0) ) ]
936
+ #[ unstable = "API still in development" ]
937
+ impl < Idx : fmt:: String > fmt:: String for Range < Idx > {
938
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
939
+ write ! ( fmt, "{}..{}" , self . start, self . end)
940
+ }
941
+ }
942
+
907
943
/// A range which is only bounded below.
908
- #[ derive( Copy ) ]
944
+ #[ derive( Copy , PartialEq , Eq ) ]
909
945
#[ lang="range_from" ]
910
946
#[ unstable = "API still in development" ]
911
947
pub struct RangeFrom < Idx > {
@@ -926,15 +962,59 @@ impl<Idx: Clone + Step> Iterator for RangeFrom<Idx> {
926
962
}
927
963
}
928
964
965
+ #[ unstable = "API still in development" ]
966
+ impl < Idx : fmt:: Show > fmt:: Show for RangeFrom < Idx > {
967
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
968
+ write ! ( fmt, "{:?}.." , self . start)
969
+ }
970
+ }
971
+
972
+ #[ cfg( stage0) ]
973
+ #[ unstable = "API still in development" ]
974
+ impl < Idx : fmt:: String + fmt:: Show > fmt:: String for RangeFrom < Idx > {
975
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
976
+ write ! ( fmt, "{}.." , self . start)
977
+ }
978
+ }
979
+ #[ cfg( not( stage0) ) ]
980
+ #[ unstable = "API still in development" ]
981
+ impl < Idx : fmt:: String > fmt:: String for RangeFrom < Idx > {
982
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
983
+ write ! ( fmt, "{}.." , self . start)
984
+ }
985
+ }
986
+
929
987
/// A range which is only bounded above.
930
- #[ derive( Copy ) ]
988
+ #[ derive( Copy , PartialEq , Eq ) ]
931
989
#[ lang="range_to" ]
932
990
#[ unstable = "API still in development" ]
933
991
pub struct RangeTo < Idx > {
934
992
/// The upper bound of the range (exclusive).
935
993
pub end : Idx ,
936
994
}
937
995
996
+ #[ unstable = "API still in development" ]
997
+ impl < Idx : fmt:: Show > fmt:: Show for RangeTo < Idx > {
998
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
999
+ write ! ( fmt, "..{:?}" , self . end)
1000
+ }
1001
+ }
1002
+
1003
+ #[ cfg( stage0) ]
1004
+ #[ unstable = "API still in development" ]
1005
+ impl < Idx : fmt:: String + fmt:: Show > fmt:: String for RangeTo < Idx > {
1006
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1007
+ write ! ( fmt, "..{}" , self . end)
1008
+ }
1009
+ }
1010
+ #[ cfg( not( stage0) ) ]
1011
+ #[ unstable = "API still in development" ]
1012
+ impl < Idx : fmt:: String > fmt:: String for RangeTo < Idx > {
1013
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1014
+ write ! ( fmt, "..{}" , self . end)
1015
+ }
1016
+ }
1017
+
938
1018
939
1019
/// The `Deref` trait is used to specify the functionality of dereferencing
940
1020
/// operations like `*v`.
0 commit comments