Skip to content

Commit f98c55d

Browse files
committed
Add documentation example for str::Chars::as_str.
1 parent feeca94 commit f98c55d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: src/libcore/str/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,19 @@ impl<'a> Chars<'a> {
459459
///
460460
/// This has the same lifetime as the original slice, and so the
461461
/// iterator can continue to be used while this exists.
462+
///
463+
/// # Examples
464+
///
465+
/// ```
466+
/// let mut chars = "abc".chars();
467+
///
468+
/// assert_eq!(chars.as_str(), "abc");
469+
/// chars.next();
470+
/// assert_eq!(chars.as_str(), "bc");
471+
/// chars.next();
472+
/// chars.next();
473+
/// assert_eq!(chars.as_str(), "");
474+
/// ```
462475
#[stable(feature = "iter_to_slice", since = "1.4.0")]
463476
#[inline]
464477
pub fn as_str(&self) -> &'a str {

0 commit comments

Comments
 (0)