Skip to content

Commit 5064106

Browse files
committed
Point out str::as_ptr is not nul-terminated
1 parent 59ce765 commit 5064106

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/src/str/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ impl str {
292292
/// The caller must ensure that the returned pointer is never written to.
293293
/// If you need to mutate the contents of the string slice, use [`as_mut_ptr`].
294294
///
295+
/// Note that the pointer returned by `as_ptr()` is *not* null-terminated.
296+
/// See [`std::ffi::CString`] if you need a pointer to a traditional
297+
/// C-style string.
298+
///
295299
/// [`as_mut_ptr`]: str::as_mut_ptr
300+
/// [`std::ffi::CString`]: ../std/ffi/struct.CString.html
296301
///
297302
/// # Examples
298303
///
@@ -317,6 +322,12 @@ impl str {
317322
///
318323
/// It is your responsibility to make sure that the string slice only gets
319324
/// modified in a way that it remains valid UTF-8.
325+
///
326+
/// Note that the pointer returned by `as_mut_ptr()` is *not* null-terminated.
327+
/// See [`std::ffi::CString`] if you need a pointer to a traditional
328+
/// C-style string.
329+
///
330+
/// [`std::ffi::CString`]: ../std/ffi/struct.CString.html
320331
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
321332
#[inline]
322333
pub fn as_mut_ptr(&mut self) -> *mut u8 {

0 commit comments

Comments
 (0)