diff options
| author | bors <bors@rust-lang.org> | 2023-08-03 02:40:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-03 02:40:19 +0000 |
| commit | d8bbef50bbad789e26219f4ec88b5d73b05570a3 (patch) | |
| tree | 82efc85db3e5fdbc68412ae3ec65bb2acc62cc43 | |
| parent | aa70e5fb6ece9c3c7373923b557925818328bd00 (diff) | |
| parent | c94dc72a1cc578da622941095104a4426161b503 (diff) | |
| download | rust-d8bbef50bbad789e26219f4ec88b5d73b05570a3.tar.gz rust-d8bbef50bbad789e26219f4ec88b5d73b05570a3.zip | |
Auto merge of #113220 - tgross35:cstr-bytes-docs, r=workingjubilee
Clarify documentation for `CStr` * Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul` * Add some links where they may be helpful
| -rw-r--r-- | library/core/src/ffi/c_str.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 549fec9477a..b59ec12790d 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -197,8 +197,8 @@ impl CStr { /// /// This function will wrap the provided `ptr` with a `CStr` wrapper, which /// allows inspection and interoperation of non-owned C strings. The total - /// size of the raw C string must be smaller than `isize::MAX` **bytes** - /// in memory due to calling the `slice::from_raw_parts` function. + /// size of the terminated buffer must be smaller than [`isize::MAX`] **bytes** + /// in memory (a restriction from [`slice::from_raw_parts`]). /// /// # Safety /// @@ -295,11 +295,11 @@ impl CStr { } } - /// Creates a C string wrapper from a byte slice. + /// Creates a C string wrapper from a byte slice with any number of nuls. /// /// This method will create a `CStr` from any byte slice that contains at - /// least one nul byte. The caller does not need to know or specify where - /// the nul byte is located. + /// least one nul byte. Unlike with [`CStr::from_bytes_with_nul`], the caller + /// does not need to know where the nul byte is located. /// /// If the first byte is a nul character, this method will return an /// empty `CStr`. If multiple nul characters are present, the `CStr` will @@ -341,7 +341,8 @@ impl CStr { } } - /// Creates a C string wrapper from a byte slice. + /// Creates a C string wrapper from a byte slice with exactly one nul + /// terminator. /// /// This function will cast the provided `bytes` to a `CStr` /// wrapper after ensuring that the byte slice is nul-terminated |
