Skip to content

Commit 3a80b22

Browse files
committed
core: impl AsRef<[u8]> for str
1 parent e6378cb commit 3a80b22

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libcore/str/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
2121
use char::CharExt;
2222
use clone::Clone;
2323
use cmp::{self, Eq};
24+
use convert::AsRef;
2425
use default::Default;
2526
use fmt;
2627
use iter::ExactSizeIterator;
@@ -1842,6 +1843,14 @@ impl StrExt for str {
18421843
fn parse<T: FromStr>(&self) -> Result<T, T::Err> { FromStr::from_str(self) }
18431844
}
18441845

1846+
#[stable(feature = "rust1", since = "1.1.0")]
1847+
impl AsRef<[u8]> for str {
1848+
#[inline]
1849+
fn as_ref(&self) -> &[u8] {
1850+
self.as_bytes()
1851+
}
1852+
}
1853+
18451854
/// Pluck a code point out of a UTF-8-like byte slice and return the
18461855
/// index of the next code point.
18471856
#[inline]

0 commit comments

Comments
 (0)