Add doc example for CString::into_bytes.

This commit is contained in:
Corey Farwell 2017-06-05 23:46:44 -04:00
parent 4db8c9f0ba
commit 3ec1f61acc

View File

@ -331,6 +331,16 @@ pub fn into_string(self) -> Result<String, IntoStringError> {
///
/// The returned buffer does **not** contain the trailing nul separator and
/// it is guaranteed to not have any interior nul bytes.
///
/// # Examples
///
/// ```
/// use std::ffi::CString;
///
/// let c_string = CString::new("foo").unwrap();
/// let bytes = c_string.into_bytes();
/// assert_eq!(bytes, vec![b'f', b'o', b'o']);
/// ```
#[stable(feature = "cstring_into", since = "1.7.0")]
pub fn into_bytes(self) -> Vec<u8> {
let mut vec = self.into_inner().into_vec();