Feature gate: #![feature(str_as_str)]
This is a tracking issue for the as_str() method on the str type itself, so that Box<str>, Rc<str>, Arc<str> & others can have the same things as String has.
Later also expanded to some other types (see below).
Public API
impl str {
pub const fn as_str(&self) -> &str;
}
impl CStr {
pub const fn as_c_str(&self) -> &CStr;
}
impl OsStr {
pub const fn as_os_str(&self) -> &OsStr;
}
impl Path {
pub const fn as_path(&self) -> &Path;
}
impl [T] {
pub const fn as_slice(&self) -> &[T];
pub const fn as_mut_slice(&mut self) -> &mut [T];
}
impl ByteStr {
pub const fn as_byte_str(&self) -> &ByteStr;
pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr;
}
Steps / History
Unresolved Questions
Feature gate:
#![feature(str_as_str)]This is a tracking issue for the
as_str()method on thestrtype itself, so thatBox<str>,Rc<str>,Arc<str>& others can have the same things asStringhas.Later also expanded to some other types (see below).
Public API
ByteStr: Tracking Issue for ByteStr/ByteString #134915Steps / History
str: Add str.as_str() for easy Deref to string slices #129550constify (the unstable)str::as_str#145930str_as_strto more types #145933str::as_strbut forCStr,OsStr,Path, and[T]libs-team#643str_as_str#151603 (comment)str_as_str#151603rgbwithas_mut_slice#152961str_as_str" #152963Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩