Skip to content

Commit d8bbef5

Browse files
committed
Auto merge of rust-lang#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
2 parents aa70e5f + c94dc72 commit d8bbef5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/core/src/ffi/c_str.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ impl CStr {
197197
///
198198
/// This function will wrap the provided `ptr` with a `CStr` wrapper, which
199199
/// allows inspection and interoperation of non-owned C strings. The total
200-
/// size of the raw C string must be smaller than `isize::MAX` **bytes**
201-
/// in memory due to calling the `slice::from_raw_parts` function.
200+
/// size of the terminated buffer must be smaller than [`isize::MAX`] **bytes**
201+
/// in memory (a restriction from [`slice::from_raw_parts`]).
202202
///
203203
/// # Safety
204204
///
@@ -295,11 +295,11 @@ impl CStr {
295295
}
296296
}
297297

298-
/// Creates a C string wrapper from a byte slice.
298+
/// Creates a C string wrapper from a byte slice with any number of nuls.
299299
///
300300
/// This method will create a `CStr` from any byte slice that contains at
301-
/// least one nul byte. The caller does not need to know or specify where
302-
/// the nul byte is located.
301+
/// least one nul byte. Unlike with [`CStr::from_bytes_with_nul`], the caller
302+
/// does not need to know where the nul byte is located.
303303
///
304304
/// If the first byte is a nul character, this method will return an
305305
/// empty `CStr`. If multiple nul characters are present, the `CStr` will
@@ -341,7 +341,8 @@ impl CStr {
341341
}
342342
}
343343

344-
/// Creates a C string wrapper from a byte slice.
344+
/// Creates a C string wrapper from a byte slice with exactly one nul
345+
/// terminator.
345346
///
346347
/// This function will cast the provided `bytes` to a `CStr`
347348
/// wrapper after ensuring that the byte slice is nul-terminated

0 commit comments

Comments
 (0)