View all comments
Feature gate: #![feature(trim_prefix_suffix)]
This is a tracking issue for adding trim_prefix and trim_suffix methods to str that remove at most one occurrence of a specified prefix or suffix while always returning a string slice (rather than Option<&str>), enabling easy method chaining.1
Public API
impl str {
pub fn trim_prefix<P>(&self, prefix: P) -> &str
where
P: Pattern;
pub fn trim_suffix<P>(&self, suffix: P) -> &str
where
P: Pattern,
for<'a> P::Searcher<'a>: ReverseSearcher<'a>;
}
impl [T] {
pub fn trim_prefix<P>(&self, prefix: &P) -> &[T]
where
P: SlicePattern<Item = T> + ?Sized,
T: PartialEq;
pub fn trim_suffix<P>(&self, suffix: &P) -> &[T]
where
P: SlicePattern<Item = T> + ?Sized,
T: PartialEq;
}
impl Path {
pub fn trim_prefix<P>(&self, base: P) -> &Path
where
P: AsRef<Path>;
}
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
Unresolved Questions
View all comments
Feature gate:
#![feature(trim_prefix_suffix)]This is a tracking issue for adding
trim_prefixandtrim_suffixmethods tostrthat remove at most one occurrence of a specified prefix or suffix while always returning a string slice (rather thanOption<&str>), enabling easy method chaining.1Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)trim_prefixandtrim_suffixmethods for bothsliceandstrtypes. #142331Unresolved Questions
Footnotes
https://github.com/rust-lang/libs-team/issues/597 ↩
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩