Skip to content

Commit b444ac6

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35621 - frewsxcv:cstring-from-vec-doc, r=peschkaj
Add doc example for `std::ffi::CString::from_vec_unchecked`. None
2 parents 74549f8 + 4e4d8ba commit b444ac6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/ffi/c_str.rs

+11
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ impl CString {
211211
/// This method is equivalent to `new` except that no runtime assertion
212212
/// is made that `v` contains no 0 bytes, and it requires an actual
213213
/// byte vector, not anything that can be converted to one with Into.
214+
///
215+
/// # Examples
216+
///
217+
/// ```
218+
/// use std::ffi::CString;
219+
///
220+
/// let raw = b"foo".to_vec();
221+
/// unsafe {
222+
/// let c_string = CString::from_vec_unchecked(raw);
223+
/// }
224+
/// ```
214225
#[stable(feature = "rust1", since = "1.0.0")]
215226
pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
216227
v.push(0);

0 commit comments

Comments
 (0)