Skip to content

Tracking Issue for strip_circumfix #147946

@yotamofek

Description

@yotamofek

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> [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

Footnotes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions