Tracking Issue for strip_circumfix (original) (raw)

Feature gate: #![feature(strip_circumfix)]

This is a tracking issue for adding the strip_circumfix method to str and the slice primitives.

These methods are a shorter and more concise way to express these prevalent patterns that appear in a lot of code:

if let Some(a) = a.strip_prefix('<') && let Some(a) = a.strip_suffix('>') {}

// or...

let a = a.strip_prefix('<').and_then(|a| a.strip_suffix('>'));

Public API

impl str { pub fn strip_circumfix<P: Pattern, S: Pattern>(&self, prefix: P, suffix: S) -> Option<&str> where for<'a> S::Searcher<'a>: ReverseSearcher<'a>; }

impl [T] { pub fn strip_circumfix(&self, prefix: &P, suffix: &S) -> Option<&[T]> where P: SlicePattern<Item = T> + ?Sized, S: SlicePattern<Item = T> + ?Sized, T: PartialEq; }

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html