Tracking Issue for ASCII trim functions on byte slices · Issue #94035 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Feature gate: #![feature(byte_slice_trim_ascii)]
This is a tracking issue for ASCII trim functions on byte slices.
Public API
The feature adds three new methods to byte slices ([u8]
):
const fn trim_ascii_start(&self) -> &[u8]
: Remove leading ASCII whitespaceconst fn trim_ascii_end(&self) -> &[u8]
: Remove trailing ASCII whitespaceconst fn trim_ascii(&self) -> &[u8]
: Remove leading and trailing ASCII whitespace
For deciding what bytes to treat as whitespace, u8::is_ascii_whitespace is used. See the linked docs for more details.
Examples:
assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n"); assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world"); assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
Steps / History
- Implementation: core: Implement ASCII trim functions on byte slices #93686
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- Should the methods be made const by using a pattern matching approach instead of indexing?
- Should corresponding methods be added to
str
as well?