Skip to content

Commit

Permalink
Rollup merge of rust-lang#35621 - frewsxcv:cstring-from-vec-doc, r=pe…
Browse files Browse the repository at this point in the history
…schkaj

Add doc example for `std::ffi::CString::from_vec_unchecked`.

None
  • Loading branch information
Jonathan Turner authored Aug 17, 2016
2 parents 74549f8 + 4e4d8ba commit b444ac6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
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 b444ac6

Please sign in to comment.