Skip to content
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

Point out str::as_ptr is not nul-terminated #88463

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ impl str {
/// The caller must ensure that the returned pointer is never written to.
/// If you need to mutate the contents of the string slice, use [`as_mut_ptr`].
///
/// Note that the pointer returned by `as_ptr()` is *not* null-terminated.
/// See [`std::ffi::CString`] if you need a pointer to a traditional
/// C-style string.
///
/// [`as_mut_ptr`]: str::as_mut_ptr
/// [`std::ffi::CString`]: ../std/ffi/struct.CString.html
///
/// # Examples
///
Expand All @@ -317,6 +322,12 @@ impl str {
///
/// It is your responsibility to make sure that the string slice only gets
/// modified in a way that it remains valid UTF-8.
///
/// Note that the pointer returned by `as_mut_ptr()` is *not* null-terminated.
/// See [`std::ffi::CString`] if you need a pointer to a traditional
/// C-style string.
///
/// [`std::ffi::CString`]: ../std/ffi/struct.CString.html
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut u8 {
Expand Down