Skip to content

Commit 41c8d3f

Browse files
Rollup merge of #35062 - frewsxcv:chars-as-str, r=GuillaumeGomez
Add documentation example for `str::Chars::as_str`. None
2 parents 72d1d06 + f98c55d commit 41c8d3f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcore/str/mod.rs

Lines changed: 13 additions & 0 deletions
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)