From 3e8fadc2ac5d5e25aaf0449d50988c54be92dbe4 Mon Sep 17 00:00:00 2001 From: Tommy Ip Date: Sat, 9 Sep 2017 09:05:54 +0100 Subject: [PATCH] Add doc example to String::as_str Fixes #44428. --- src/liballoc/string.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index ddb23b2ef37..1708f3e3987 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -743,6 +743,16 @@ pub fn into_bytes(self) -> Vec { } /// 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 { -- 2.44.0