@@ -2519,14 +2519,15 @@ impl<T> [T] {
2519
2519
cmp:: SliceContains :: slice_contains ( x, self )
2520
2520
}
2521
2521
2522
- /// Returns `true` if `needle` is a prefix of the slice.
2522
+ /// Returns `true` if `needle` is a prefix of the slice or equal to the slice .
2523
2523
///
2524
2524
/// # Examples
2525
2525
///
2526
2526
/// ```
2527
2527
/// let v = [10, 40, 30];
2528
2528
/// assert!(v.starts_with(&[10]));
2529
2529
/// assert!(v.starts_with(&[10, 40]));
2530
+ /// assert!(v.starts_with(&v));
2530
2531
/// assert!(!v.starts_with(&[50]));
2531
2532
/// assert!(!v.starts_with(&[10, 50]));
2532
2533
/// ```
@@ -2549,14 +2550,15 @@ impl<T> [T] {
2549
2550
self . len ( ) >= n && needle == & self [ ..n]
2550
2551
}
2551
2552
2552
- /// Returns `true` if `needle` is a suffix of the slice.
2553
+ /// Returns `true` if `needle` is a suffix of the slice or equal to the slice .
2553
2554
///
2554
2555
/// # Examples
2555
2556
///
2556
2557
/// ```
2557
2558
/// let v = [10, 40, 30];
2558
2559
/// assert!(v.ends_with(&[30]));
2559
2560
/// assert!(v.ends_with(&[40, 30]));
2561
+ /// assert!(v.ends_with(&v));
2560
2562
/// assert!(!v.ends_with(&[50]));
2561
2563
/// assert!(!v.ends_with(&[50, 30]));
2562
2564
/// ```
@@ -2582,7 +2584,8 @@ impl<T> [T] {
2582
2584
/// Returns a subslice with the prefix removed.
2583
2585
///
2584
2586
/// If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`.
2585
- /// If `prefix` is empty, simply returns the original slice.
2587
+ /// If `prefix` is empty, simply returns the original slice. If `prefix` is equal to the
2588
+ /// original slice, returns an empty slice.
2586
2589
///
2587
2590
/// If the slice does not start with `prefix`, returns `None`.
2588
2591
///
@@ -2592,6 +2595,7 @@ impl<T> [T] {
2592
2595
/// let v = &[10, 40, 30];
2593
2596
/// assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..]));
2594
2597
/// assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..]));
2598
+ /// assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..]));
2595
2599
/// assert_eq!(v.strip_prefix(&[50]), None);
2596
2600
/// assert_eq!(v.strip_prefix(&[10, 50]), None);
2597
2601
///
@@ -2620,7 +2624,8 @@ impl<T> [T] {
2620
2624
/// Returns a subslice with the suffix removed.
2621
2625
///
2622
2626
/// If the slice ends with `suffix`, returns the subslice before the suffix, wrapped in `Some`.
2623
- /// If `suffix` is empty, simply returns the original slice.
2627
+ /// If `suffix` is empty, simply returns the original slice. If `suffix` is equal to the
2628
+ /// original slice, returns an empty slice.
2624
2629
///
2625
2630
/// If the slice does not end with `suffix`, returns `None`.
2626
2631
///
@@ -2630,6 +2635,7 @@ impl<T> [T] {
2630
2635
/// let v = &[10, 40, 30];
2631
2636
/// assert_eq!(v.strip_suffix(&[30]), Some(&[10, 40][..]));
2632
2637
/// assert_eq!(v.strip_suffix(&[40, 30]), Some(&[10][..]));
2638
+ /// assert_eq!(v.strip_suffix(&[10, 40, 30]), Some(&[][..]));
2633
2639
/// assert_eq!(v.strip_suffix(&[50]), None);
2634
2640
/// assert_eq!(v.strip_suffix(&[50, 30]), None);
2635
2641
/// ```
0 commit comments