@@ -690,6 +690,19 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
690690 } ,
691691 }
692692 }
693+
694+ #[ inline]
695+ fn as_str ( & self ) -> & ' a str {
696+ // `Self::get_end` doesn't change `self.start`
697+ if self . finished {
698+ return "" ;
699+ }
700+
701+ // SAFETY: `self.start` and `self.end` always lie on unicode boundaries.
702+ unsafe {
703+ self . matcher . haystack ( ) . get_unchecked ( self . start ..self . end )
704+ }
705+ }
693706}
694707
695708generate_pattern_iterators ! {
@@ -710,6 +723,48 @@ generate_pattern_iterators! {
710723 delegate double ended;
711724}
712725
726+ impl < ' a , P : Pattern < ' a > > Split < ' a , P > {
727+ /// Returns remainder of the splitted string
728+ ///
729+ /// # Examples
730+ ///
731+ /// ```
732+ /// #![feature(str_split_as_str)]
733+ /// let mut split = "Mary had a little lamb".split(' ');
734+ /// assert_eq!(split.as_str(), "Mary had a little lamb");
735+ /// split.next();
736+ /// assert_eq!(split.as_str(), "had a little lamb");
737+ /// split.by_ref().for_each(drop);
738+ /// assert_eq!(split.as_str(), "");
739+ /// ```
740+ #[ inline]
741+ #[ unstable( feature = "str_split_as_str" , issue = "none" ) ]
742+ pub fn as_str ( & self ) -> & ' a str {
743+ self . 0 . as_str ( )
744+ }
745+ }
746+
747+ impl < ' a , P : Pattern < ' a > > RSplit < ' a , P > {
748+ /// Returns remainder of the splitted string
749+ ///
750+ /// # Examples
751+ ///
752+ /// ```
753+ /// #![feature(str_split_as_str)]
754+ /// let mut split = "Mary had a little lamb".rsplit(' ');
755+ /// assert_eq!(split.as_str(), "Mary had a little lamb");
756+ /// split.next();
757+ /// assert_eq!(split.as_str(), "Mary had a little");
758+ /// split.by_ref().for_each(drop);
759+ /// assert_eq!(split.as_str(), "");
760+ /// ```
761+ #[ inline]
762+ #[ unstable( feature = "str_split_as_str" , issue = "none" ) ]
763+ pub fn as_str ( & self ) -> & ' a str {
764+ self . 0 . as_str ( )
765+ }
766+ }
767+
713768generate_pattern_iterators ! {
714769 forward:
715770 /// Created with the method [`split_terminator`].
0 commit comments