str::as_str but for CStr, OsStr, Path, and [T] (original) (raw)

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

rust-lang/rust#145933

Questions