about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJorge Aparicio <japaricious@gmail.com>2014-11-23 13:13:17 -0500
committerJorge Aparicio <japaricious@gmail.com>2014-11-23 13:21:24 -0500
commit02720a4a1665ebdca6159f5189115bdf3087afbf (patch)
tree61a4cd8dc87c06073073698e8a5885f82148312e
parent220b99b148559e8996a1dbd279e8ca190bf94b2e (diff)
downloadrust-02720a4a1665ebdca6159f5189115bdf3087afbf.tar.gz
rust-02720a4a1665ebdca6159f5189115bdf3087afbf.zip
DSTify Str + impl Str for &S where S: Str
-rw-r--r--src/libcore/str.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 3b2a7c62312..bb7710c2acc 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -1277,14 +1277,19 @@ pub mod traits {
 }
 
 /// Any string that can be represented as a slice
-pub trait Str {
+pub trait Str for Sized? {
     /// Work with `self` as a slice.
     fn as_slice<'a>(&'a self) -> &'a str;
 }
 
-impl<'a> Str for &'a str {
+impl Str for str {
     #[inline]
-    fn as_slice<'a>(&'a self) -> &'a str { *self }
+    fn as_slice<'a>(&'a self) -> &'a str { self }
+}
+
+impl<'a, Sized? S> Str for &'a S where S: Str {
+    #[inline]
+    fn as_slice(&self) -> &str { Str::as_slice(*self) }
 }
 
 /// Methods for string slices