Skip to content

Commit

Permalink
Add doc example for std::ffi::CString::from_vec_unchecked.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Aug 12, 2016
1 parent f55ac69 commit 4e4d8ba
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -211,6 +211,17 @@ impl CString {
/// This method is equivalent to `new` except that no runtime assertion
/// is made that `v` contains no 0 bytes, and it requires an actual
/// byte vector, not anything that can be converted to one with Into.
///
/// # Examples
///
/// ```
/// use std::ffi::CString;
///
/// let raw = b"foo".to_vec();
/// unsafe {
/// let c_string = CString::from_vec_unchecked(raw);
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
v.push(0);
Expand Down

0 comments on commit 4e4d8ba

Please sign in to comment.