From e7f3d6eddd28a917c9a0f7cd73a489048ca7f4cd Mon Sep 17 00:00:00 2001 From: William Throwe Date: Sun, 1 Nov 2015 00:21:47 -0400 Subject: Let str::replace take a pattern It appears this was left out of RFC #528 because it might be useful to also generalize the second argument in some way. That doesn't seem to prevent generalizing the first argument now, however. This is a [breaking-change] because it could cause type-inference to fail where it previously succeeded. --- src/libcollections/str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcollections') diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index be3f93992d9..989637517b0 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1706,7 +1706,7 @@ impl str { /// assert_eq!(s, s.replace("cookie monster", "little lamb")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn replace(&self, from: &str, to: &str) -> String { + pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String { let mut result = String::new(); let mut last_end = 0; for (start, part) in self.match_indices(from) { -- cgit 1.4.1-3-g733a5