From 02720a4a1665ebdca6159f5189115bdf3087afbf Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 23 Nov 2014 13:13:17 -0500 Subject: [PATCH] DSTify Str + impl Str for &S where S: Str --- src/libcore/str.rs | 11 ++++++++--- 1 file 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