mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 04:55:22 +03:00
std: Stabilize CString/OsString/PathBuf extra methods
Stabilizes: * `CString::as_c_str` * `CString::into_boxed_c_str` * `CStr::into_c_string` * `OsString::into_boxed_os_str` * `OsStr::into_os_string` * `PathBuf::into_boxed_path` * `PathBuf::into_path_buf` Closes #40380
This commit is contained in:
@@ -462,7 +462,7 @@ pub fn as_bytes_with_nul(&self) -> &[u8] {
|
||||
/// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "as_c_str", issue = "40380")]
|
||||
#[stable(feature = "as_c_str", since = "1.20.0")]
|
||||
pub fn as_c_str(&self) -> &CStr {
|
||||
&*self
|
||||
}
|
||||
@@ -482,7 +482,7 @@ pub fn as_c_str(&self) -> &CStr {
|
||||
/// let boxed = c_string.into_boxed_c_str();
|
||||
/// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap());
|
||||
/// ```
|
||||
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_c_str", since = "1.20.0")]
|
||||
pub fn into_boxed_c_str(self) -> Box<CStr> {
|
||||
unsafe { mem::transmute(self.into_inner()) }
|
||||
}
|
||||
@@ -1009,7 +1009,7 @@ pub fn to_string_lossy(&self) -> Cow<str> {
|
||||
/// let boxed = c_string.into_boxed_c_str();
|
||||
/// assert_eq!(boxed.into_c_string(), CString::new("foo").unwrap());
|
||||
/// ```
|
||||
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_c_str", since = "1.20.0")]
|
||||
pub fn into_c_string(self: Box<CStr>) -> CString {
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ pub fn shrink_to_fit(&mut self) {
|
||||
///
|
||||
/// let b: Box<OsStr> = s.into_boxed_os_str();
|
||||
/// ```
|
||||
#[unstable(feature = "into_boxed_os_str", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_os_str", since = "1.20.0")]
|
||||
pub fn into_boxed_os_str(self) -> Box<OsStr> {
|
||||
unsafe { mem::transmute(self.inner.into_box()) }
|
||||
}
|
||||
@@ -511,7 +511,7 @@ pub fn len(&self) -> usize {
|
||||
///
|
||||
/// [`Box`]: ../boxed/struct.Box.html
|
||||
/// [`OsString`]: struct.OsString.html
|
||||
#[unstable(feature = "into_boxed_os_str", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_os_str", since = "1.20.0")]
|
||||
pub fn into_os_string(self: Box<OsStr>) -> OsString {
|
||||
let inner: Box<Slice> = unsafe { mem::transmute(self) };
|
||||
OsString { inner: Buf::from_box(inner) }
|
||||
|
||||
+2
-2
@@ -1327,7 +1327,7 @@ pub fn into_os_string(self) -> OsString {
|
||||
///
|
||||
/// [`Box`]: ../../std/boxed/struct.Box.html
|
||||
/// [`Path`]: struct.Path.html
|
||||
#[unstable(feature = "into_boxed_path", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_path", since = "1.20.0")]
|
||||
pub fn into_boxed_path(self) -> Box<Path> {
|
||||
unsafe { mem::transmute(self.inner.into_boxed_os_str()) }
|
||||
}
|
||||
@@ -2300,7 +2300,7 @@ pub fn is_dir(&self) -> bool {
|
||||
///
|
||||
/// [`Box`]: ../../std/boxed/struct.Box.html
|
||||
/// [`PathBuf`]: struct.PathBuf.html
|
||||
#[unstable(feature = "into_boxed_path", issue = "40380")]
|
||||
#[stable(feature = "into_boxed_path", since = "1.20.0")]
|
||||
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
|
||||
let inner: Box<OsStr> = unsafe { mem::transmute(self) };
|
||||
PathBuf { inner: OsString::from(inner) }
|
||||
|
||||
Reference in New Issue
Block a user