Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

thing_as_thing #145933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
GrigorenkoPV wants to merge 2 commits into rust-lang:master
base: master
Choose a base branch
Loading
from GrigorenkoPV:thing_as_thing
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions library/core/src/ffi/c_str.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,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 = "thing_as_thing", issue = "none")]
pub const fn as_c_str(&self) -> &CStr {
self
}
}

#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
Expand Down
22 changes: 22 additions & 0 deletions library/core/src/slice/mod.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,28 @@ impl<T> [T] {

if start <= self.len() && end <= self.len() { Some(start..end) } else { None }
}

/// Returns the same slice `&[T]`.
///
/// This method is redundant when used directly on `&[T]`, but
/// it helps dereferencing other "container" types to slices,
/// for example `Box<[T]>` or `Arc<[T]>`.
#[inline]
#[unstable(feature = "thing_as_thing", issue = "none")]
pub const fn as_slice(&self) -> &[T] {
self
}

/// Returns the same slice `&mut [T]`.
///
/// This method is redundant when used directly on `&mut [T]`, but
/// it helps dereferencing other "container" types to slices,
/// for example `Box<[T]>` or `Arc<[T]>`.
#[inline]
#[unstable(feature = "thing_as_thing", issue = "none")]
pub const fn as_mut_slice(&mut self) -> &mut [T] {
self
}
}

impl<T> [MaybeUninit<T>] {
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/ffi/os_str.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,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 = "thing_as_thing", issue = "none")]
pub const fn as_os_str(&self) -> &OsStr {
self
}
}

#[stable(feature = "box_from_os_str", since = "1.17.0")]
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/path.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2993,6 +2993,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 = "thing_as_thing", issue = "none")]
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
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /