@@ -691,15 +691,40 @@ impl<T> [T] {
691
691
///
692
692
/// # Examples
693
693
///
694
- /// Print the slice split by numbers divisible by 3 (i.e. `[10, 40]`,
695
- /// `[20]`, `[50]`):
694
+ /// ```
695
+ /// let slice = [10, 40, 33, 20];
696
+ /// let mut iter = slice.split(|num| num % 3 == 0);
696
697
///
698
+ /// assert_eq!(iter.next().unwrap(), &[10, 40]);
699
+ /// assert_eq!(iter.next().unwrap(), &[20]);
700
+ /// assert!(iter.next().is_none());
697
701
/// ```
698
- /// let v = [10, 40, 30, 20, 60, 50];
699
702
///
700
- /// for group in v.split(|num| *num % 3 == 0) {
701
- /// println!("{:?}", group);
702
- /// }
703
+ /// If the first element is matched, an empty slice will be the first item
704
+ /// returned by the iterator. Similarly, if the last element in the slice
705
+ /// is matched, an empty slice will be the last item returned by the
706
+ /// iterator:
707
+ ///
708
+ /// ```
709
+ /// let slice = [10, 40, 33];
710
+ /// let mut iter = slice.split(|num| num % 3 == 0);
711
+ ///
712
+ /// assert_eq!(iter.next().unwrap(), &[10, 40]);
713
+ /// assert_eq!(iter.next().unwrap(), &[]);
714
+ /// assert!(iter.next().is_none());
715
+ /// ```
716
+ ///
717
+ /// If two matched elements are directly adjacent, an empty slice will be
718
+ /// present between them:
719
+ ///
720
+ /// ```
721
+ /// let slice = [10, 6, 33, 20];
722
+ /// let mut iter = slice.split(|num| num % 3 == 0);
723
+ ///
724
+ /// assert_eq!(iter.next().unwrap(), &[10]);
725
+ /// assert_eq!(iter.next().unwrap(), &[]);
726
+ /// assert_eq!(iter.next().unwrap(), &[20]);
727
+ /// assert!(iter.next().is_none());
703
728
/// ```
704
729
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
705
730
#[ inline]
0 commit comments