@@ -979,6 +979,86 @@ impl<T> RangeBounds<T> for RangeToInclusive<&T> {
979979 }
980980}
981981
982+ /// Used to convert a range into start and end bounds, consuming the
983+ /// range by value.
984+ ///
985+ /// `IntoBounds` is implemented by Rust’s built-in range types, produced
986+ /// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
987+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
988+ pub trait IntoBounds < T : Sized > : RangeBounds < T > {
989+ /// Convert this range into the start and end bounds.
990+ /// Returns `(start_bound, end_bound)`.
991+ ///
992+ /// # Examples
993+ ///
994+ /// ```
995+ /// use std::ops::Bound::*;
996+ /// use std::ops::IntoBounds;
997+ ///
998+ /// assert_eq!((0..5).into_bounds(), (Included(0), Excluded(5)));
999+ /// assert_eq!((..=7).into_bounds(), (Unbounded, Included(7)));
1000+ /// ```
1001+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) ;
1002+ }
1003+
1004+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1005+ impl < T > IntoBounds < T > for Range < T > {
1006+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1007+ ( Included ( self . start ) , Excluded ( self . end ) )
1008+ }
1009+ }
1010+
1011+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1012+ impl < T > IntoBounds < T > for RangeFrom < T > {
1013+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1014+ ( Included ( self . start ) , Unbounded )
1015+ }
1016+ }
1017+
1018+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1019+ impl < T > IntoBounds < T > for RangeFull {
1020+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1021+ ( Unbounded , Unbounded )
1022+ }
1023+ }
1024+
1025+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1026+ impl < T > IntoBounds < T > for RangeInclusive < T > {
1027+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1028+ (
1029+ Included ( self . start ) ,
1030+ if self . exhausted {
1031+ // When the iterator is exhausted, we usually have start == end,
1032+ // but we want the range to appear empty, containing nothing.
1033+ Excluded ( self . end )
1034+ } else {
1035+ Included ( self . end )
1036+ } ,
1037+ )
1038+ }
1039+ }
1040+
1041+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1042+ impl < T > IntoBounds < T > for RangeTo < T > {
1043+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1044+ ( Unbounded , Excluded ( self . end ) )
1045+ }
1046+ }
1047+
1048+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1049+ impl < T > IntoBounds < T > for RangeToInclusive < T > {
1050+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1051+ ( Unbounded , Included ( self . end ) )
1052+ }
1053+ }
1054+
1055+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
1056+ impl < T > IntoBounds < T > for ( Bound < T > , Bound < T > ) {
1057+ fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
1058+ self
1059+ }
1060+ }
1061+
9821062/// An internal helper for `split_off` functions indicating
9831063/// which end a `OneSidedRange` is bounded on.
9841064#[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
0 commit comments