Skip to content

Commit c0992f5

Browse files
authored
Rollup merge of #107464 - WaffleLapkin:all_that_remains_of_lines, r=dtolnay
Add `str::Lines::remainder` Based on #98453. This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](#77998).
2 parents 69db514 + cce93f0 commit c0992f5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

library/core/src/str/iter.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,31 @@ impl<'a> DoubleEndedIterator for Lines<'a> {
11871187
#[stable(feature = "fused", since = "1.26.0")]
11881188
impl FusedIterator for Lines<'_> {}
11891189

1190+
impl<'a> Lines<'a> {
1191+
/// Returns the remaining lines of the split string.
1192+
///
1193+
/// # Examples
1194+
///
1195+
/// ```
1196+
/// #![feature(str_lines_remainder)]
1197+
///
1198+
/// let mut lines = "a\nb\nc\nd".lines();
1199+
/// assert_eq!(lines.remainder(), Some("a\nb\nc\nd"));
1200+
///
1201+
/// lines.next();
1202+
/// assert_eq!(lines.remainder(), Some("b\nc\nd"));
1203+
///
1204+
/// lines.by_ref().for_each(drop);
1205+
/// assert_eq!(lines.remainder(), None);
1206+
/// ```
1207+
#[inline]
1208+
#[must_use]
1209+
#[unstable(feature = "str_lines_remainder", issue = "77998")]
1210+
pub fn remainder(&self) -> Option<&'a str> {
1211+
self.0.iter.remainder()
1212+
}
1213+
}
1214+
11901215
/// Created with the method [`lines_any`].
11911216
///
11921217
/// [`lines_any`]: str::lines_any

0 commit comments

Comments
 (0)