@@ -2725,6 +2725,38 @@ impl<T> [T] {
27252725 None
27262726 }
27272727
2728+ /// Returns a subslice with the prefix and suffix removed.
2729+ ///
2730+ /// If the slice starts with `prefix` and ends with `suffix`, returns the subslice after the
2731+ /// prefix and before the suffix, wrapped in `Some`.
2732+ ///
2733+ /// If the slice does not start with `prefix` or does not end with `suffix`, returns `None`.
2734+ ///
2735+ /// # Examples
2736+ ///
2737+ /// ```
2738+ /// #![feature(strip_circumfix)]
2739+ ///
2740+ /// let v = &[10, 50, 40, 30];
2741+ /// assert_eq!(v.strip_circumfix(&[10], &[30]), Some(&[50, 40][..]));
2742+ /// assert_eq!(v.strip_circumfix(&[10], &[40, 30]), Some(&[50][..]));
2743+ /// assert_eq!(v.strip_circumfix(&[10, 50], &[40, 30]), Some(&[][..]));
2744+ /// assert_eq!(v.strip_circumfix(&[50], &[30]), None);
2745+ /// assert_eq!(v.strip_circumfix(&[10], &[40]), None);
2746+ /// assert_eq!(v.strip_circumfix(&[], &[40, 30]), Some(&[10, 50][..]));
2747+ /// assert_eq!(v.strip_circumfix(&[10, 50], &[]), Some(&[40, 30][..]));
2748+ /// ```
2749+ #[ must_use = "returns the subslice without modifying the original" ]
2750+ #[ unstable( feature = "strip_circumfix" , issue = "147946" ) ]
2751+ pub fn strip_circumfix < S , P > ( & self , prefix : & P , suffix : & S ) -> Option < & [ T ] >
2752+ where
2753+ T : PartialEq ,
2754+ S : SlicePattern < Item = T > + ?Sized ,
2755+ P : SlicePattern < Item = T > + ?Sized ,
2756+ {
2757+ self . strip_prefix ( prefix) ?. strip_suffix ( suffix)
2758+ }
2759+
27282760 /// Returns a subslice with the optional prefix removed.
27292761 ///
27302762 /// If the slice starts with `prefix`, returns the subslice after the prefix. If `prefix`
0 commit comments