@@ -705,35 +705,6 @@ pub trait RangeBounds<T: ?Sized> {
705
705
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
706
706
fn end_bound ( & self ) -> Bound < & T > ;
707
707
708
- /// Returns `true` if `item` is contained in the range.
709
- ///
710
- /// # Examples
711
- ///
712
- /// ```
713
- /// assert!( (3..5).contains(&4));
714
- /// assert!(!(3..5).contains(&2));
715
- ///
716
- /// assert!( (0.0..1.0).contains(&0.5));
717
- /// assert!(!(0.0..1.0).contains(&f32::NAN));
718
- /// assert!(!(0.0..f32::NAN).contains(&0.5));
719
- /// assert!(!(f32::NAN..1.0).contains(&0.5));
720
- #[ stable( feature = "range_contains" , since = "1.35.0" ) ]
721
- fn contains < U > ( & self , item : & U ) -> bool
722
- where
723
- T : PartialOrd < U > ,
724
- U : ?Sized + PartialOrd < T > ,
725
- {
726
- ( match self . start_bound ( ) {
727
- Included ( ref start) => * start <= item,
728
- Excluded ( ref start) => * start < item,
729
- Unbounded => true ,
730
- } ) && ( match self . end_bound ( ) {
731
- Included ( ref end) => item <= * end,
732
- Excluded ( ref end) => item < * end,
733
- Unbounded => true ,
734
- } )
735
- }
736
-
737
708
/// Performs bounds-checking of this range.
738
709
///
739
710
/// The returned [`Range`] is safe to pass to [`slice::get_unchecked`] and
@@ -749,46 +720,46 @@ pub trait RangeBounds<T: ?Sized> {
749
720
/// # Examples
750
721
///
751
722
/// ```
752
- /// #![feature(range_bounds_for_length )]
723
+ /// #![feature(range_bounds_assert_len )]
753
724
///
754
725
/// use std::ops::RangeBounds;
755
726
///
756
727
/// let v = [10, 40, 30];
757
- /// assert_eq!(1..2, (1..2).for_length (v.len()));
758
- /// assert_eq!(0..2, (..2).for_length (v.len()));
759
- /// assert_eq!(1..3, (1..).for_length (v.len()));
728
+ /// assert_eq!(1..2, (1..2).assert_len (v.len()));
729
+ /// assert_eq!(0..2, (..2).assert_len (v.len()));
730
+ /// assert_eq!(1..3, (1..).assert_len (v.len()));
760
731
/// ```
761
732
///
762
733
/// Panics when [`Index::index`] would panic:
763
734
///
764
735
/// ```should_panic
765
- /// #![feature(range_bounds_for_length )]
736
+ /// #![feature(range_bounds_assert_len )]
766
737
///
767
738
/// use std::ops::RangeBounds;
768
739
///
769
- /// (2..1).for_length (3);
740
+ /// (2..1).assert_len (3);
770
741
/// ```
771
742
///
772
743
/// ```should_panic
773
- /// #![feature(range_bounds_for_length )]
744
+ /// #![feature(range_bounds_assert_len )]
774
745
///
775
746
/// use std::ops::RangeBounds;
776
747
///
777
- /// (1..4).for_length (3);
748
+ /// (1..4).assert_len (3);
778
749
/// ```
779
750
///
780
751
/// ```should_panic
781
- /// #![feature(range_bounds_for_length )]
752
+ /// #![feature(range_bounds_assert_len )]
782
753
///
783
754
/// use std::ops::RangeBounds;
784
755
///
785
- /// (1..=usize::MAX).for_length (3);
756
+ /// (1..=usize::MAX).assert_len (3);
786
757
/// ```
787
758
///
788
759
/// [`Index::index`]: crate::ops::Index::index
789
760
#[ track_caller]
790
- #[ unstable( feature = "range_bounds_for_length " , issue = "76393" ) ]
791
- fn for_length ( self , len : usize ) -> Range < usize >
761
+ #[ unstable( feature = "range_bounds_assert_len " , issue = "76393" ) ]
762
+ fn assert_len ( self , len : usize ) -> Range < usize >
792
763
where
793
764
Self : RangeBounds < usize > ,
794
765
{
@@ -819,6 +790,35 @@ pub trait RangeBounds<T: ?Sized> {
819
790
820
791
Range { start, end }
821
792
}
793
+
794
+ /// Returns `true` if `item` is contained in the range.
795
+ ///
796
+ /// # Examples
797
+ ///
798
+ /// ```
799
+ /// assert!( (3..5).contains(&4));
800
+ /// assert!(!(3..5).contains(&2));
801
+ ///
802
+ /// assert!( (0.0..1.0).contains(&0.5));
803
+ /// assert!(!(0.0..1.0).contains(&f32::NAN));
804
+ /// assert!(!(0.0..f32::NAN).contains(&0.5));
805
+ /// assert!(!(f32::NAN..1.0).contains(&0.5));
806
+ #[ stable( feature = "range_contains" , since = "1.35.0" ) ]
807
+ fn contains < U > ( & self , item : & U ) -> bool
808
+ where
809
+ T : PartialOrd < U > ,
810
+ U : ?Sized + PartialOrd < T > ,
811
+ {
812
+ ( match self . start_bound ( ) {
813
+ Included ( ref start) => * start <= item,
814
+ Excluded ( ref start) => * start < item,
815
+ Unbounded => true ,
816
+ } ) && ( match self . end_bound ( ) {
817
+ Included ( ref end) => item <= * end,
818
+ Excluded ( ref end) => item < * end,
819
+ Unbounded => true ,
820
+ } )
821
+ }
822
822
}
823
823
824
824
use self :: Bound :: { Excluded , Included , Unbounded } ;
0 commit comments