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_bytes
1 parent ae4832d commit 06f63f5Copy full SHA for 06f63f5
src/libstd/ffi/c_str.rs
@@ -372,6 +372,16 @@ impl CString {
372
///
373
/// The returned slice does **not** contain the trailing nul separator and
374
/// it is guaranteed to not have any interior nul bytes.
375
+ ///
376
+ /// # Examples
377
378
+ /// ```
379
+ /// use std::ffi::CString;
380
381
+ /// let c_string = CString::new("foo").unwrap();
382
+ /// let bytes = c_string.as_bytes();
383
+ /// assert_eq!(bytes, &[b'f', b'o', b'o']);
384
385
#[stable(feature = "rust1", since = "1.0.0")]
386
pub fn as_bytes(&self) -> &[u8] {
387
&self.inner[..self.inner.len() - 1]
0 commit comments