Rollup merge of #107464 - WaffleLapkin:all_that_remains_of_lines, r=dtolnay

Add `str::Lines::remainder`

Based on https://github.com/rust-lang/rust/pull/98453.

This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](https://github.com/rust-lang/rust/issues/77998).
This commit is contained in:
Matthias Krüger 2024-01-26 06:36:36 +01:00 committed by GitHub
commit c0992f5ce1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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