Skip to content

Commit

Permalink
Document that CStr::as_ptr returns a type alias
Browse files Browse the repository at this point in the history
Workaround for rust-lang#15823
  • Loading branch information
kornelski committed Feb 16, 2023
1 parent af3c8b2 commit fd89470
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ impl CStr {
/// to a contiguous region of memory terminated with a 0 byte to represent
/// the end of the string.
///
/// The type of the returned pointer is
/// [`*const c_char`][crate::ffi::c_char], and whether it's
/// an alias for `*const i8` or `*const u8` is platform-specific.
///
/// **WARNING**
///
/// The returned pointer is read-only; writing to it (including passing it
Expand All @@ -470,6 +474,7 @@ impl CStr {
/// # #![allow(unused_must_use)] #![allow(temporary_cstring_as_ptr)]
/// use std::ffi::CString;
///
/// // Do not do this:
/// let ptr = CString::new("Hello").expect("CString::new failed").as_ptr();
/// unsafe {
/// // `ptr` is dangling
Expand Down

0 comments on commit fd89470

Please sign in to comment.