diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-23 15:10:30 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-23 15:10:30 -0700 |
| commit | bed77408df6b279d1d3b67c07e77c8d40e496f2e (patch) | |
| tree | d3ab43eb7ec3c750c241a5cd95f6b919cbe68075 /src/libcollections/string.rs | |
| parent | 9e347b39f105a2ab416fc518ee51225882a6d996 (diff) | |
| parent | 76ead081088d7cc88a4686210b72b60ae12bd7a8 (diff) | |
| download | rust-bed77408df6b279d1d3b67c07e77c8d40e496f2e.tar.gz rust-bed77408df6b279d1d3b67c07e77c8d40e496f2e.zip | |
rollup merge of #23580: nikomatsakis/pattern-and-overflow
Diffstat (limited to 'src/libcollections/string.rs')
| -rw-r--r-- | src/libcollections/string.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 6463949ac8a..a5d788143b0 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] |
