mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Stabilize byte_slice_trim_ascii
for &[u8]
/&str
Remove feature from documentation examples Add rustc_const_stable attribute to stabilized functions Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions
This commit is contained in:
parent
6f7e00a3e6
commit
9fb49faf40
@ -114,18 +114,17 @@ impl [u8] {
|
||||
/// Returns a byte slice with leading ASCII whitespace bytes removed.
|
||||
///
|
||||
/// 'Whitespace' refers to the definition used by
|
||||
/// `u8::is_ascii_whitespace`.
|
||||
/// [`u8::is_ascii_whitespace`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n");
|
||||
/// assert_eq!(b" ".trim_ascii_start(), b"");
|
||||
/// assert_eq!(b"".trim_ascii_start(), b"");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii_start(&self) -> &[u8] {
|
||||
let mut bytes = self;
|
||||
@ -144,18 +143,17 @@ impl [u8] {
|
||||
/// Returns a byte slice with trailing ASCII whitespace bytes removed.
|
||||
///
|
||||
/// 'Whitespace' refers to the definition used by
|
||||
/// `u8::is_ascii_whitespace`.
|
||||
/// [`u8::is_ascii_whitespace`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world");
|
||||
/// assert_eq!(b" ".trim_ascii_end(), b"");
|
||||
/// assert_eq!(b"".trim_ascii_end(), b"");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii_end(&self) -> &[u8] {
|
||||
let mut bytes = self;
|
||||
@ -175,18 +173,17 @@ impl [u8] {
|
||||
/// removed.
|
||||
///
|
||||
/// 'Whitespace' refers to the definition used by
|
||||
/// `u8::is_ascii_whitespace`.
|
||||
/// [`u8::is_ascii_whitespace`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
|
||||
/// assert_eq!(b" ".trim_ascii(), b"");
|
||||
/// assert_eq!(b"".trim_ascii(), b"");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii(&self) -> &[u8] {
|
||||
self.trim_ascii_start().trim_ascii_end()
|
||||
|
@ -2531,15 +2531,14 @@ impl str {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!(" \t \u{3000}hello world\n".trim_ascii_start(), "\u{3000}hello world\n");
|
||||
/// assert_eq!(" ".trim_ascii_start(), "");
|
||||
/// assert_eq!("".trim_ascii_start(), "");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[must_use = "this returns the trimmed string as a new slice, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii_start(&self) -> &str {
|
||||
// SAFETY: Removing ASCII characters from a `&str` does not invalidate
|
||||
@ -2557,15 +2556,14 @@ impl str {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!("\r hello world\u{3000}\n ".trim_ascii_end(), "\r hello world\u{3000}");
|
||||
/// assert_eq!(" ".trim_ascii_end(), "");
|
||||
/// assert_eq!("".trim_ascii_end(), "");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[must_use = "this returns the trimmed string as a new slice, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii_end(&self) -> &str {
|
||||
// SAFETY: Removing ASCII characters from a `&str` does not invalidate
|
||||
@ -2584,15 +2582,14 @@ impl str {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(byte_slice_trim_ascii)]
|
||||
///
|
||||
/// assert_eq!("\r hello world\n ".trim_ascii(), "hello world");
|
||||
/// assert_eq!(" ".trim_ascii(), "");
|
||||
/// assert_eq!("".trim_ascii(), "");
|
||||
/// ```
|
||||
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
|
||||
#[must_use = "this returns the trimmed string as a new slice, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "byte_slice_trim_ascii", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
pub const fn trim_ascii(&self) -> &str {
|
||||
// SAFETY: Removing ASCII characters from a `&str` does not invalidate
|
||||
|
Loading…
Reference in New Issue
Block a user