Registry Mirror
Skip to content

File tree

‎library/core/src/slice/mod.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,10 +2738,12 @@ impl<T> [T] {
27382738

27392739
/// Returns a subslice with the prefix and suffix removed.
27402740
///
2741-
/// If the slice starts with `prefix` and ends with `suffix`, returns the subslice after the
2742-
/// prefix and before the suffix, wrapped in `Some`.
2741+
/// If the slice starts with `prefix`, ends with `suffix`, and
2742+
/// the prefix and suffix don't overlap, returns the subslice after
2743+
/// the prefix and before the suffix, wrapped in `Some`.
27432744
///
2744-
/// If the slice does not start with `prefix` or does not end with `suffix`, returns `None`.
2745+
/// If the slice does not start with `prefix`, does not end with `suffix`,
2746+
/// or the prefix and suffix overlap in the slice, returns `None`.
27452747
///
27462748
/// # Examples
27472749
///
@@ -2754,6 +2756,7 @@ impl<T> [T] {
27542756
/// assert_eq!(v.strip_circumfix(&[10], &[40]), None);
27552757
/// assert_eq!(v.strip_circumfix(&[], &[40, 30]), Some(&[10, 50][..]));
27562758
/// assert_eq!(v.strip_circumfix(&[10, 50], &[]), Some(&[40, 30][..]));
2759+
/// assert_eq!(v.strip_circumfix(&[10, 50, 40], &[50, 40, 30]), None);
27572760
/// ```
27582761
#[must_use = "returns the subslice without modifying the original"]
27592762
#[stable(feature = "strip_circumfix", since = "CURRENT_RUSTC_VERSION")]

‎library/core/src/str/mod.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,12 +2492,14 @@ impl str {
24922492

24932493
/// Returns a string slice with the prefix and suffix removed.
24942494
///
2495-
/// If the string starts with the pattern `prefix` and ends with the pattern `suffix`, returns
2495+
/// If the string starts with the pattern `prefix` and ends with
2496+
/// the pattern `suffix`, and the prefix and suffix don't overlap, returns
24962497
/// the substring after the prefix and before the suffix, wrapped in `Some`.
24972498
/// Unlike [`trim_start_matches`] and [`trim_end_matches`], this method removes both the prefix
24982499
/// and suffix exactly once.
24992500
///
2500-
/// If the string does not start with `prefix` or does not end with `suffix`, returns `None`.
2501+
/// If the string does not start with `prefix`, does not end with `suffix`,
2502+
/// or the prefix and suffix overlap in the string, returns `None`.
25012503
///
25022504
/// Each [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
25032505
/// function or closure that determines if a character matches.
@@ -2513,6 +2515,7 @@ impl str {
25132515
/// assert_eq!("bar:hello:foo".strip_circumfix("bar:", ":foo"), Some("hello"));
25142516
/// assert_eq!("bar:foo".strip_circumfix("foo", "foo"), None);
25152517
/// assert_eq!("foo:bar;".strip_circumfix("foo:", ';'), Some("bar"));
2518+
/// assert_eq!("foo:bar:baz".strip_circumfix("foo:bar:", ":bar:baz"), None);
25162519
/// ```
25172520
#[must_use = "this returns the remaining substring as a new slice, \
25182521
without modifying the original"]

0 commit comments

Comments
 (0)