mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-28 19:27:30 +03:00
{CStr,OsStr,Path}::as_$1
This commit is contained in:
@@ -648,6 +648,17 @@ pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
|
||||
pub fn display(&self) -> impl fmt::Display {
|
||||
crate::bstr::ByteStr::from_bytes(self.to_bytes())
|
||||
}
|
||||
|
||||
/// Returns the same string as a string slice `&CStr`.
|
||||
///
|
||||
/// This method is redundant when used directly on `&CStr`, but
|
||||
/// it helps dereferencing other string-like types to string slices,
|
||||
/// for example references to `Box<CStr>` or `Arc<CStr>`.
|
||||
#[inline]
|
||||
#[unstable(feature = "str_as_str", issue = "130366")]
|
||||
pub const fn as_c_str(&self) -> &CStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
|
||||
|
||||
@@ -1278,6 +1278,17 @@ pub fn eq_ignore_ascii_case<S: AsRef<OsStr>>(&self, other: S) -> bool {
|
||||
pub fn display(&self) -> Display<'_> {
|
||||
Display { os_str: self }
|
||||
}
|
||||
|
||||
/// Returns the same string as a string slice `&OsStr`.
|
||||
///
|
||||
/// This method is redundant when used directly on `&OsStr`, but
|
||||
/// it helps dereferencing other string-like types to string slices,
|
||||
/// for example references to `Box<OsStr>` or `Arc<OsStr>`.
|
||||
#[inline]
|
||||
#[unstable(feature = "str_as_str", issue = "130366")]
|
||||
pub const fn as_os_str(&self) -> &OsStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_os_str", since = "1.17.0")]
|
||||
|
||||
@@ -3208,6 +3208,17 @@ pub fn display(&self) -> Display<'_> {
|
||||
Display { inner: self.inner.display() }
|
||||
}
|
||||
|
||||
/// Returns the same path as `&Path`.
|
||||
///
|
||||
/// This method is redundant when used directly on `&Path`, but
|
||||
/// it helps dereferencing other `PathBuf`-like types to `Path`s,
|
||||
/// for example references to `Box<Path>` or `Arc<Path>`.
|
||||
#[inline]
|
||||
#[unstable(feature = "str_as_str", issue = "130366")]
|
||||
pub const fn as_path(&self) -> &Path {
|
||||
self
|
||||
}
|
||||
|
||||
/// Queries the file system to get information about a file, directory, etc.
|
||||
///
|
||||
/// This function will traverse symbolic links to query information about the
|
||||
|
||||
Reference in New Issue
Block a user