-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Description
Proposal
Add CStr::as_c_str
, OsStr::as_os_str
, Path::as_path
, [T]::as_slice
, and [T]::as_mut_slice
, analogous to str::as_str
(rust-lang/rust#130366) to aid dereferencing Box<CStr/OsStr/...>
without CString
, OsString
, ... being the only ones with the convenient .as_thing()
method.
Background
str::as_str
was proposed by t-libs-api in rust-lang/rust#129550 (comment) as a response to a PR adding Box<str>::as_str
.
The idea of analogous additions for other "slicy" types was brought up in rust-lang/rust#130366 (comment)
Solution sketch
Questions
- Should this reuse the same feature gate as
str::as_str
? - Should the
[T]::
methods be moved to a separate feature gate? - Bikeshed the feature gate names.
- Technically slices already have an
as_slice
method, but with nomut
version and it comes from an unstable trait with a closed tracking issue and docs saying that hopefully this trait will be removed in the future: https://doc.rust-lang.org/stable/std/primitive.slice.html#impl-SlicePattern-for-%5BT%5D
Metadata
Metadata
Assignees
Labels
T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries