From f98c55d933d24a806cee85bb0239682b39a23e32 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 26 Jul 2016 22:52:56 -0400 Subject: [PATCH] Add documentation example for `str::Chars::as_str`. --- src/libcore/str/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index a32c9da9815..fdcadd43a0f 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -459,6 +459,19 @@ impl<'a> Chars<'a> { /// /// This has the same lifetime as the original slice, and so the /// iterator can continue to be used while this exists. + /// + /// # Examples + /// + /// ``` + /// let mut chars = "abc".chars(); + /// + /// assert_eq!(chars.as_str(), "abc"); + /// chars.next(); + /// assert_eq!(chars.as_str(), "bc"); + /// chars.next(); + /// chars.next(); + /// assert_eq!(chars.as_str(), ""); + /// ``` #[stable(feature = "iter_to_slice", since = "1.4.0")] #[inline] pub fn as_str(&self) -> &'a str {