]> git.lizzy.rs Git - rust.git/commitdiff
core: impl AsRef<[u8]> for str
authorSean McArthur <sean.monstar@gmail.com>
Wed, 6 May 2015 22:53:34 +0000 (15:53 -0700)
committerSean McArthur <sean.monstar@gmail.com>
Sat, 9 May 2015 00:13:54 +0000 (17:13 -0700)
src/libcore/str/mod.rs

index c9bbcba31e9de28009118823df32c32693d2f3e9..c10e1443cfcbebefb79092e8e5fc3b8353c642f6 100644 (file)
@@ -21,6 +21,7 @@
 use char::CharExt;
 use clone::Clone;
 use cmp::{self, Eq};
+use convert::AsRef;
 use default::Default;
 use fmt;
 use iter::ExactSizeIterator;
@@ -1842,6 +1843,14 @@ fn is_empty(&self) -> bool { self.len() == 0 }
     fn parse<T: FromStr>(&self) -> Result<T, T::Err> { FromStr::from_str(self) }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl AsRef<[u8]> for str {
+    #[inline]
+    fn as_ref(&self) -> &[u8] {
+        self.as_bytes()
+    }
+}
+
 /// Pluck a code point out of a UTF-8-like byte slice and return the
 /// index of the next code point.
 #[inline]