Skip to content

Commit

Permalink
Rollup merge of rust-lang#107464 - WaffleLapkin:all_that_remains_of_l…
Browse files Browse the repository at this point in the history
…ines, r=dtolnay

Add `str::Lines::remainder`

Based on rust-lang#98453.

This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](rust-lang#77998).
  • Loading branch information
matthiaskrgr authored Jan 26, 2024
2 parents 69db514 + cce93f0 commit c0992f5
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 @@ -1187,6 +1187,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 c0992f5

Please sign in to comment.