8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Pattern
1 parent 9fc6710 commit d76c965Copy full SHA for d76c965
alloc/src/str.rs
@@ -269,7 +269,7 @@ impl str {
269
without modifying the original"]
270
#[stable(feature = "rust1", since = "1.0.0")]
271
#[inline]
272
- pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
+ pub fn replace<P: Pattern>(&self, from: P, to: &str) -> String {
273
let mut result = String::new();
274
let mut last_end = 0;
275
for (start, part) in self.match_indices(from) {
@@ -309,7 +309,7 @@ impl str {
309
#[must_use = "this returns the replaced string as a new allocation, \
310
311
#[stable(feature = "str_replacen", since = "1.16.0")]
312
- pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
+ pub fn replacen<P: Pattern>(&self, pat: P, to: &str, count: usize) -> String {
313
// Hope to reduce the times of re-allocation
314
let mut result = String::with_capacity(32);
315
alloc/src/string.rs
@@ -1497,10 +1497,7 @@ impl String {
1497
/// ```
1498
#[cfg(not(no_global_oom_handling))]
1499
#[unstable(feature = "string_remove_matches", reason = "new API", issue = "72826")]
1500
- pub fn remove_matches<'a, P>(&'a mut self, pat: P)
1501
- where
1502
- P: for<'x> Pattern<'x>,
1503
- {
+ pub fn remove_matches<P: Pattern>(&mut self, pat: P) {
1504
use core::str::pattern::Searcher;
1505
1506
let rejections = {
@@ -2288,35 +2285,41 @@ impl<'a> Extend<Cow<'a, str>> for String {
2288
2285
reason = "API not fully fleshed out and ready to be stabilized",
2289
2286
issue = "27721"
2290
2287
)]
2291
-impl<'a, 'b> Pattern<'a> for &'b String {
2292
- type Searcher = <&'b str as Pattern<'a>>::Searcher;
+impl<'b> Pattern for &'b String {
+ type Searcher<'a> = <&'b str as Pattern>::Searcher<'a>;
2293
2294
- fn into_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher {
+ fn into_searcher(self, haystack: &str) -> <&'b str as Pattern>::Searcher<'_> {
2295
self[..].into_searcher(haystack)
2296
}
2297
2298
2299
- fn is_contained_in(self, haystack: &'a str) -> bool {
+ fn is_contained_in(self, haystack: &str) -> bool {
2300
self[..].is_contained_in(haystack)
2301
2302
2303
2304
- fn is_prefix_of(self, haystack: &'a str) -> bool {
+ fn is_prefix_of(self, haystack: &str) -> bool {
2305
self[..].is_prefix_of(haystack)
2306
2307
2308
2309
- fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
+ fn strip_prefix_of(self, haystack: &str) -> Option<&str> {
2310
self[..].strip_prefix_of(haystack)
2311
2312
2313
2314
- fn is_suffix_of(self, haystack: &'a str) -> bool {
+ fn is_suffix_of<'a>(self, haystack: &'a str) -> bool
+ where
+ Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>,
+ {
2315
self[..].is_suffix_of(haystack)
2316
2317
2318
2319
- fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> {
+ fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&str>
2320
2321
2322
2323
self[..].strip_suffix_of(haystack)
2324
2325
alloc/tests/str.rs
@@ -1927,12 +1927,10 @@ mod pattern {
1927
1928
1929
1930
- fn cmp_search_to_vec<'a>(
1931
- rev: bool,
1932
- pat: impl Pattern<'a, Searcher: ReverseSearcher<'a>>,
1933
- haystack: &'a str,
1934
- right: Vec<SearchStep>,
1935
- ) {
+ fn cmp_search_to_vec<P>(rev: bool, pat: P, haystack: &str, right: Vec<SearchStep>)
+ P: for<'a> Pattern<Searcher<'a>: ReverseSearcher<'a>>,
1936
let mut searcher = pat.into_searcher(haystack);
1937
let mut v = vec![];
1938
loop {
@@ -2191,9 +2189,9 @@ generate_iterator_test! {
2191
2189
fn different_str_pattern_forwarding_lifetimes() {
2192
2190
use std::str::pattern::Pattern;
2193
2194
- fn foo<'a, P>(p: P)
+ fn foo<P>(p: P)
2195
where
2196
- for<'b> &'b P: Pattern<'a>,
+ for<'b> &'b P: Pattern,
2197
{
2198
for _ in 0..3 {
2199
"asdf".find(&p);