mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
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:
commit
c0992f5ce1
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user