From 76ead081088d7cc88a4686210b72b60ae12bd7a8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 21 Mar 2015 06:02:56 -0400 Subject: Remove auto-deref'ing Pattern impl because it conflicts with other possible blanket impls and also triggers internal overflow. Add some special cases for common uses (&&str, &String) for now; bounds-targeting deref coercions are probably the right longer term answer. --- src/libcollections/string.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libcollections') diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cd6f27bf65f..7eccd5fa3b6 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -25,6 +25,7 @@ use core::mem; use core::ops::{self, Deref, Add, Index}; use core::ptr; use core::slice; +use core::str::Pattern; use unicode::str as unicode_str; use unicode::str::Utf16Item; @@ -765,6 +766,25 @@ impl<'a> Extend<&'a str> for String { } } +/// A convenience impl that delegates to the impl for `&str` +impl<'a, 'b> Pattern<'a> for &'b String { + type Searcher = <&'b str as Pattern<'a>>::Searcher; + + fn into_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher { + self[..].into_searcher(haystack) + } + + #[inline] + fn is_contained_in(self, haystack: &'a str) -> bool { + self[..].is_contained_in(haystack) + } + + #[inline] + fn is_prefix_of(self, haystack: &'a str) -> bool { + self[..].is_prefix_of(haystack) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for String { #[inline] -- cgit 1.4.1-3-g733a5