add str::SplitInclusive::as_str
method
This commit entroduces `core::str::SplitInclusive::as_str` method similar to `core::str::Split::as_str`, but under different gate - "str_split_inclusive_as_str" (this is done so because `SplitInclusive` is itself unstable).
This commit is contained in:
parent
4747215d77
commit
076514c8a8
@ -126,6 +126,7 @@
|
||||
#![feature(std_internals)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(str_split_as_str)]
|
||||
#![feature(str_split_inclusive_as_str)]
|
||||
#![feature(transparent_unions)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unsized_locals)]
|
||||
|
@ -699,9 +699,7 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
|
||||
}
|
||||
|
||||
// SAFETY: `self.start` and `self.end` always lie on unicode boundaries.
|
||||
unsafe {
|
||||
self.matcher.haystack().get_unchecked(self.start..self.end)
|
||||
}
|
||||
unsafe { self.matcher.haystack().get_unchecked(self.start..self.end) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1278,6 +1276,28 @@ impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
|
||||
#[unstable(feature = "split_inclusive", issue = "72360")]
|
||||
impl<'a, P: Pattern<'a>> FusedIterator for SplitInclusive<'a, P> {}
|
||||
|
||||
impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> {
|
||||
/// Returns remainder of the splitted string
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(str_split_inclusive_as_str)]
|
||||
/// #![feature(split_inclusive)]
|
||||
/// let mut split = "Mary had a little lamb".split_inclusive(' ');
|
||||
/// assert_eq!(split.as_str(), "Mary had a little lamb");
|
||||
/// split.next();
|
||||
/// assert_eq!(split.as_str(), "had a little lamb");
|
||||
/// split.by_ref().for_each(drop);
|
||||
/// assert_eq!(split.as_str(), "");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "str_split_inclusive_as_str", issue = "none")]
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator of [`u16`] over the string encoded as UTF-16.
|
||||
///
|
||||
/// This struct is created by the [`encode_utf16`] method on [`str`].
|
||||
|
Loading…
x
Reference in New Issue
Block a user