Skip to content

Commit

Permalink
Add str::Lines::remainder
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jan 30, 2023
1 parent f55b002 commit cce93f0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions library/core/src/str/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,31 @@ impl<'a> DoubleEndedIterator for Lines<'a> {
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for Lines<'_> {}

impl<'a> Lines<'a> {
/// Returns the remaining lines of the split string.
///
/// # Examples
///
/// ```
/// #![feature(str_lines_remainder)]
///
/// let mut lines = "a\nb\nc\nd".lines();
/// assert_eq!(lines.remainder(), Some("a\nb\nc\nd"));
///
/// lines.next();
/// assert_eq!(lines.remainder(), Some("b\nc\nd"));
///
/// lines.by_ref().for_each(drop);
/// assert_eq!(lines.remainder(), None);
/// ```
#[inline]
#[must_use]
#[unstable(feature = "str_lines_remainder", issue = "77998")]
pub fn remainder(&self) -> Option<&'a str> {
self.0.iter.remainder()
}
}

/// Created with the method [`lines_any`].
///
/// [`lines_any`]: str::lines_any
Expand Down

0 comments on commit cce93f0

Please sign in to comment.