File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -221,9 +221,7 @@ impl CStr {
221221 /// # Examples
222222 ///
223223 /// ```ignore (extern-declaration)
224- /// # fn main() {
225- /// use std::ffi::CStr;
226- /// use std::os::raw::c_char;
224+ /// use std::ffi::{c_char, CStr};
227225 ///
228226 /// extern "C" {
229227 /// fn my_string() -> *const c_char;
@@ -233,7 +231,18 @@ impl CStr {
233231 /// let slice = CStr::from_ptr(my_string());
234232 /// println!("string returned: {}", slice.to_str().unwrap());
235233 /// }
236- /// # }
234+ /// ```
235+ ///
236+ /// ```
237+ /// #![feature(const_cstr_methods)]
238+ ///
239+ /// use std::ffi::{c_char, CStr};
240+ ///
241+ /// const HELLO_PTR: *const c_char = {
242+ /// const BYTES: &[u8] = b"Hello, world!\0";
243+ /// BYTES.as_ptr().cast()
244+ /// };
245+ /// const HELLO: &CStr = unsafe { CStr::from_ptr(HELLO_PTR) };
237246 /// ```
238247 ///
239248 /// [valid]: core::ptr#safety
You can’t perform that action at this time.
0 commit comments