rust/library/std/src
Michael Goulet aee4570adf
Rollup merge of #107429 - tgross35:from-bytes-until-null-stabilization, r=dtolnay
Stabilize feature `cstr_from_bytes_until_nul`

This PR seeks to stabilize `cstr_from_bytes_until_nul`.

Partially addresses #95027

This function has only been on nightly for about 10 months, but I think it is simple enough that there isn't harm discussing stabilization. It has also had at least a handful of mentions on both the user forum and the discord, so it seems like it's already in use or at least known.

This needs FCP still.

Comment on potential discussion points:
- eventual conversion of `CStr` to be a single thin pointer: this function will still be useful to provide a safe way to create a `CStr` after this change.
- should this return a length too, to address concerns about the `CStr` change? I don't see it as being particularly useful, and it seems less ergonomic (i.e. returning `Result<(&CStr, usize), FromBytesUntilNulError>`). I think users that also need this length without the additional `strlen` call are likely better off using a combination of other methods, but this is up for discussion
- `CString::from_vec_until_nul`: this is also useful, but it doesn't even have a nightly implementation merged yet. I propose feature gating that separately, as opposed to blocking this `CStr` implementation on that

Possible alternatives:

A user can use `from_bytes_with_nul` on a slice up to `my_slice[..my_slice.iter().find(|c| c == 0).unwrap()]`. However; that is significantly less ergonomic, and is a bit more work for the compiler to optimize compared the direct `memchr` call that this wraps.

## New stable API

```rs
// both in core::ffi

pub struct FromBytesUntilNulError(());

impl CStr {
    pub const fn from_bytes_until_nul(
        bytes: &[u8]
    ) -> Result<&CStr, FromBytesUntilNulError>
}
```

cc ```@ericseppanen``` original author, ```@Mark-Simulacrum``` original reviewer, ```@m-ou-se``` brought up some issues on the thin pointer CStr

```@rustbot``` modify labels: +T-libs-api +needs-fcp
2023-02-08 20:01:24 -08:00
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Fix typo in HashMap::with_capacity 2023-02-05 10:13:30 -08:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error remove fn backtrace 2022-08-01 20:10:40 +00:00
f32 Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
f64 Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
ffi Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
fs Replace libc::{type} with crate::ffi::{type} 2023-01-28 11:24:13 +05:30
io std: add tracking issue for RawOsError 2023-02-08 12:35:27 +01:00
net Replace unwrap with ? in TcpListener doc 2023-01-31 21:04:49 +00:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Rollup merge of #107317 - ids1024:asfd-rc, r=dtolnay 2023-02-08 20:01:24 -08:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path make many std tests work in Miri 2022-08-18 18:07:39 -04:00
personality Replace libc::{type} with crate::ffi::{type} 2023-01-28 11:24:13 +05:30
prelude Update bootstrap cfg 2022-12-28 09:18:43 -05:00
process More verbose Debug implementation of std::process:Command 2022-12-27 09:50:01 +01:00
sync remove optimistic spinning from mpsc::SyncSender 2023-01-14 00:36:51 -05:00
sys Rollup merge of #107154 - glaubitz:m68k-alloc, r=JohnTitor 2023-01-29 06:14:17 +01:00
sys_common Replace libc::{type} with crate::ffi::{type} 2023-01-28 11:24:13 +05:30
thread refactor[std]: do not use box syntax 2023-01-17 14:08:35 +01:00
time Fix non-associativity of Instant math on aarch64-apple-darwin targets 2022-11-13 12:01:42 -08:00
alloc.rs default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to match std handler 2023-01-02 16:35:14 +01:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
env.rs Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplett 2022-12-11 23:36:44 +01:00
error.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
f32.rs Clarify wording on f64::round() and f32::round() 2023-02-05 19:44:21 -08:00
f64.rs Clarify wording on f64::round() and f32::round() 2023-02-05 19:44:21 -08:00
fs.rs Fix some missed double spaces. 2023-01-14 18:26:38 +01:00
keyword_docs.rs review feedback 2022-10-07 15:21:47 +02:00
lib.rs Stabilize feature 'cstr_from_bytes_until_nul' 2023-02-01 02:14:07 -05:00
macros.rs Add tidy check for dbg 2022-12-31 15:32:09 +05:30
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Clarify catch_unwind docs about panic hooks 2022-12-28 16:54:42 +01:00
panicking.rs Remove various double spaces in source comments. 2023-01-14 17:22:04 +01:00
path.rs Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2023-01-31 19:24:29 +00:00
personality.rs Move personality functions to std 2022-08-23 16:12:58 +08:00
primitive_docs.rs disable strict-provenance-violating doctests in Miri 2022-11-22 11:49:02 +01:00
process.rs delete more cfg(bootstrap) 2022-12-28 09:18:43 -05:00
rt.rs Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
time.rs docs: remove colon from time header 2023-01-28 16:07:34 -07:00