Skip to content

Clarify documentation for CStr #113220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down