]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example to String::as_str
authorTommy Ip <hkmp7tommy@gmail.com>
Sat, 9 Sep 2017 08:05:54 +0000 (09:05 +0100)
committerTommy Ip <hkmp7tommy@gmail.com>
Sat, 9 Sep 2017 08:05:54 +0000 (09:05 +0100)
Fixes #44428.

src/liballoc/string.rs

index ddb23b2ef37bf0898d72db4e213d96b4fa70e5a5..1708f3e398756d493b22d8ec6c8810363c6ede06 100644 (file)
@@ -743,6 +743,16 @@ pub fn into_bytes(self) -> Vec<u8> {
     }
 
     /// Extracts a string slice containing the entire string.
+    ///
+    /// # Examples
+    ///
+    /// Basic usage:
+    ///
+    /// ```
+    /// let s = String::from("foo");
+    ///
+    /// assert_eq!("foo", s.as_str());
+    /// ```
     #[inline]
     #[stable(feature = "string_as_str", since = "1.7.0")]
     pub fn as_str(&self) -> &str {