mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
add str::{SplitN, RSplitN, SplitTerminator, RSplitTerminator}::as_str
methods
This commit entroduce 4 methods smililar to `Split::as_str` all under the same gate "str_split_as_str".
This commit is contained in:
parent
0b923d3ca0
commit
4747215d77
@ -783,6 +783,48 @@ generate_pattern_iterators! {
|
||||
delegate double ended;
|
||||
}
|
||||
|
||||
impl<'a, P: Pattern<'a>> SplitTerminator<'a, P> {
|
||||
/// Returns remainder of the splitted string
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(str_split_as_str)]
|
||||
/// let mut split = "A..B..".split_terminator('.');
|
||||
/// assert_eq!(split.as_str(), "A..B..");
|
||||
/// split.next();
|
||||
/// assert_eq!(split.as_str(), ".B..");
|
||||
/// split.by_ref().for_each(drop);
|
||||
/// assert_eq!(split.as_str(), "");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "str_split_as_str", issue = "none")]
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P: Pattern<'a>> RSplitTerminator<'a, P> {
|
||||
/// Returns remainder of the splitted string
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(str_split_as_str)]
|
||||
/// let mut split = "A..B..".rsplit_terminator('.');
|
||||
/// assert_eq!(split.as_str(), "A..B..");
|
||||
/// split.next();
|
||||
/// assert_eq!(split.as_str(), "A..B");
|
||||
/// split.by_ref().for_each(drop);
|
||||
/// assert_eq!(split.as_str(), "");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "str_split_as_str", issue = "none")]
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
derive_pattern_clone! {
|
||||
clone SplitNInternal
|
||||
with |s| SplitNInternal { iter: s.iter.clone(), ..*s }
|
||||
@ -839,6 +881,11 @@ impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_str(&self) -> &'a str {
|
||||
self.iter.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
generate_pattern_iterators! {
|
||||
@ -859,6 +906,48 @@ generate_pattern_iterators! {
|
||||
delegate single ended;
|
||||
}
|
||||
|
||||
impl<'a, P: Pattern<'a>> SplitN<'a, P> {
|
||||
/// Returns remainder of the splitted string
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(str_split_as_str)]
|
||||
/// let mut split = "Mary had a little lamb".splitn(3, ' ');
|
||||
/// 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_as_str", issue = "none")]
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P: Pattern<'a>> RSplitN<'a, P> {
|
||||
/// Returns remainder of the splitted string
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(str_split_as_str)]
|
||||
/// let mut split = "Mary had a little lamb".rsplitn(3, ' ');
|
||||
/// assert_eq!(split.as_str(), "Mary had a little lamb");
|
||||
/// split.next();
|
||||
/// assert_eq!(split.as_str(), "Mary had a little");
|
||||
/// split.by_ref().for_each(drop);
|
||||
/// assert_eq!(split.as_str(), "");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "str_split_as_str", issue = "none")]
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
derive_pattern_clone! {
|
||||
clone MatchIndicesInternal
|
||||
with |s| MatchIndicesInternal(s.0.clone())
|
||||
|
Loading…
Reference in New Issue
Block a user