We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
CString::as_c_str
1 parent 65793b3 commit 0962394Copy full SHA for 0962394
src/libstd/ffi/c_str.rs
@@ -412,6 +412,18 @@ impl CString {
412
/// Extracts a [`CStr`] slice containing the entire string.
413
///
414
/// [`CStr`]: struct.CStr.html
415
+ ///
416
+ /// # Examples
417
418
+ /// ```
419
+ /// #![feature(as_c_str)]
420
421
+ /// use std::ffi::{CString, CStr};
422
423
+ /// let c_string = CString::new(b"foo".to_vec()).unwrap();
424
+ /// let c_str = c_string.as_c_str();
425
+ /// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
426
427
#[inline]
428
#[unstable(feature = "as_c_str", issue = "40380")]
429
pub fn as_c_str(&self) -> &CStr {
0 commit comments