Skip to content

Commit 02720a4

Browse files
author
Jorge Aparicio
committed
DSTify Str + impl Str for &S where S: Str
1 parent 220b99b commit 02720a4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libcore/str.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,14 +1277,19 @@ pub mod traits {
12771277
}
12781278

12791279
/// Any string that can be represented as a slice
1280-
pub trait Str {
1280+
pub trait Str for Sized? {
12811281
/// Work with `self` as a slice.
12821282
fn as_slice<'a>(&'a self) -> &'a str;
12831283
}
12841284

1285-
impl<'a> Str for &'a str {
1285+
impl Str for str {
12861286
#[inline]
1287-
fn as_slice<'a>(&'a self) -> &'a str { *self }
1287+
fn as_slice<'a>(&'a self) -> &'a str { self }
1288+
}
1289+
1290+
impl<'a, Sized? S> Str for &'a S where S: Str {
1291+
#[inline]
1292+
fn as_slice(&self) -> &str { Str::as_slice(*self) }
12881293
}
12891294

12901295
/// Methods for string slices

0 commit comments

Comments
 (0)