File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -221,9 +221,7 @@ impl CStr {
221
221
/// # Examples
222
222
///
223
223
/// ```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};
227
225
///
228
226
/// extern "C" {
229
227
/// fn my_string() -> *const c_char;
@@ -233,7 +231,18 @@ impl CStr {
233
231
/// let slice = CStr::from_ptr(my_string());
234
232
/// println!("string returned: {}", slice.to_str().unwrap());
235
233
/// }
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) };
237
246
/// ```
238
247
///
239
248
/// [valid]: core::ptr#safety
You can’t perform that action at this time.
0 commit comments