about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-01-30 10:35:08 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-01-30 10:35:08 +0000
commitcce93f0a04ebaa4a1807f2e7f43d47839926ba94 (patch)
treeccfe2591d0c832d456729787a9e04f6049be6c61
parentf55b0022db8dccc6aa6bf3f650b562eaec0fdc54 (diff)
downloadrust-cce93f0a04ebaa4a1807f2e7f43d47839926ba94.tar.gz
rust-cce93f0a04ebaa4a1807f2e7f43d47839926ba94.zip
Add `str::Lines::remainder`
-rw-r--r--library/core/src/str/iter.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index d969475aa48..fffa421a646 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -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