@@ -979,20 +979,58 @@ impl<T> RangeBounds<T> for RangeToInclusive<&T> {
979
979
}
980
980
}
981
981
982
+ /// An internal helper for `split_off` functions indicating
983
+ /// which end a `OneSidedRange` is bounded on.
984
+ #[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
985
+ #[ allow( missing_debug_implementations) ]
986
+ pub enum OneSidedRangeBound {
987
+ /// The range is bounded inclusively from below and is unbounded above.
988
+ StartInclusive ,
989
+ /// The range is bounded exclusively from above and is unbounded below.
990
+ End ,
991
+ /// The range is bounded inclusively from above and is unbounded below.
992
+ EndInclusive ,
993
+ }
994
+
982
995
/// `OneSidedRange` is implemented for built-in range types that are unbounded
983
996
/// on one side. For example, `a..`, `..b` and `..=c` implement `OneSidedRange`,
984
997
/// but `..`, `d..e`, and `f..=g` do not.
985
998
///
986
999
/// Types that implement `OneSidedRange<T>` must return `Bound::Unbounded`
987
1000
/// from one of `RangeBounds::start_bound` or `RangeBounds::end_bound`.
988
1001
#[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
989
- pub trait OneSidedRange < T : ?Sized > : RangeBounds < T > { }
1002
+ pub trait OneSidedRange < T : ?Sized > : RangeBounds < T > {
1003
+ /// An internal-only helper function for `split_off` and
1004
+ /// `split_off_mut` that returns the bound of the one-sided range.
1005
+ fn bound ( self ) -> ( OneSidedRangeBound , T ) ;
1006
+ }
990
1007
991
1008
#[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
992
- impl < T > OneSidedRange < T > for RangeTo < T > where Self : RangeBounds < T > { }
1009
+ impl < T > OneSidedRange < T > for RangeTo < T >
1010
+ where
1011
+ Self : RangeBounds < T > ,
1012
+ {
1013
+ fn bound ( self ) -> ( OneSidedRangeBound , T ) {
1014
+ ( OneSidedRangeBound :: End , self . end )
1015
+ }
1016
+ }
993
1017
994
1018
#[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
995
- impl < T > OneSidedRange < T > for RangeFrom < T > where Self : RangeBounds < T > { }
1019
+ impl < T > OneSidedRange < T > for RangeFrom < T >
1020
+ where
1021
+ Self : RangeBounds < T > ,
1022
+ {
1023
+ fn bound ( self ) -> ( OneSidedRangeBound , T ) {
1024
+ ( OneSidedRangeBound :: StartInclusive , self . start )
1025
+ }
1026
+ }
996
1027
997
1028
#[ unstable( feature = "one_sided_range" , issue = "69780" ) ]
998
- impl < T > OneSidedRange < T > for RangeToInclusive < T > where Self : RangeBounds < T > { }
1029
+ impl < T > OneSidedRange < T > for RangeToInclusive < T >
1030
+ where
1031
+ Self : RangeBounds < T > ,
1032
+ {
1033
+ fn bound ( self ) -> ( OneSidedRangeBound , T ) {
1034
+ ( OneSidedRangeBound :: EndInclusive , self . end )
1035
+ }
1036
+ }
0 commit comments