{CStr,OsStr,Path}::as_$1
This commit is contained in:
parent
2636cb4c13
commit
a197ebdb07
3 changed files with 33 additions and 0 deletions
|
|
@ -648,6 +648,17 @@ impl CStr {
|
|||
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 @@ impl OsStr {
|
|||
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 @@ impl Path {
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue