diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-07-26 22:52:56 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-07-28 08:54:48 -0400 |
| commit | f98c55d933d24a806cee85bb0239682b39a23e32 (patch) | |
| tree | 507b457d48ba91355aaaecf7d41e03f22d3dea17 /src/libcore | |
| parent | feeca945738ffc6d252ae0fbb2f35723e4eb95a6 (diff) | |
| download | rust-f98c55d933d24a806cee85bb0239682b39a23e32.tar.gz rust-f98c55d933d24a806cee85bb0239682b39a23e32.zip | |
Add documentation example for `str::Chars::as_str`.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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 { |
