@@ -384,7 +384,7 @@ impl CString {
384384 /// fn some_extern_function(s: *mut c_char);
385385 /// }
386386 ///
387- /// let c_string = CString::new( "Hello!").expect("CString::new failed ");
387+ /// let c_string = CString::from(c "Hello!");
388388 /// let raw = c_string.into_raw();
389389 /// unsafe {
390390 /// some_extern_function(raw);
@@ -429,7 +429,7 @@ impl CString {
429429 /// ```
430430 /// use std::ffi::CString;
431431 ///
432- /// let c_string = CString::new( "foo").expect("CString::new failed ");
432+ /// let c_string = CString::from(c "foo");
433433 ///
434434 /// let ptr = c_string.into_raw();
435435 ///
@@ -487,7 +487,7 @@ impl CString {
487487 /// ```
488488 /// use std::ffi::CString;
489489 ///
490- /// let c_string = CString::new( "foo").expect("CString::new failed ");
490+ /// let c_string = CString::from(c "foo");
491491 /// let bytes = c_string.into_bytes();
492492 /// assert_eq!(bytes, vec![b'f', b'o', b'o']);
493493 /// ```
@@ -508,7 +508,7 @@ impl CString {
508508 /// ```
509509 /// use std::ffi::CString;
510510 ///
511- /// let c_string = CString::new( "foo").expect("CString::new failed ");
511+ /// let c_string = CString::from(c "foo");
512512 /// let bytes = c_string.into_bytes_with_nul();
513513 /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']);
514514 /// ```
@@ -530,7 +530,7 @@ impl CString {
530530 /// ```
531531 /// use std::ffi::CString;
532532 ///
533- /// let c_string = CString::new( "foo").expect("CString::new failed ");
533+ /// let c_string = CString::from(c "foo");
534534 /// let bytes = c_string.as_bytes();
535535 /// assert_eq!(bytes, &[b'f', b'o', b'o']);
536536 /// ```
@@ -550,7 +550,7 @@ impl CString {
550550 /// ```
551551 /// use std::ffi::CString;
552552 ///
553- /// let c_string = CString::new( "foo").expect("CString::new failed ");
553+ /// let c_string = CString::from(c "foo");
554554 /// let bytes = c_string.as_bytes_with_nul();
555555 /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
556556 /// ```
@@ -568,7 +568,7 @@ impl CString {
568568 /// ```
569569 /// use std::ffi::{CString, CStr};
570570 ///
571- /// let c_string = CString::new(b "foo".to_vec()).expect("CString::new failed ");
571+ /// let c_string = CString::from(c "foo");
572572 /// let cstr = c_string.as_c_str();
573573 /// assert_eq!(cstr,
574574 /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
@@ -586,12 +586,9 @@ impl CString {
586586 /// # Examples
587587 ///
588588 /// ```
589- /// use std::ffi::{CString, CStr};
590- ///
591- /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed");
589+ /// let c_string = c"foo".to_owned();
592590 /// let boxed = c_string.into_boxed_c_str();
593- /// assert_eq!(&*boxed,
594- /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
591+ /// assert_eq!(boxed.to_bytes_with_nul(), b"foo\0");
595592 /// ```
596593 #[ must_use = "`self` will be dropped if the result is not used" ]
597594 #[ stable( feature = "into_boxed_c_str" , since = "1.20.0" ) ]
@@ -658,7 +655,7 @@ impl CString {
658655 /// assert_eq!(
659656 /// CString::from_vec_with_nul(b"abc\0".to_vec())
660657 /// .expect("CString::from_vec_with_nul failed"),
661- /// CString::new(b "abc".to_vec()).expect("CString::new failed" )
658+ /// c "abc".to_owned( )
662659 /// );
663660 /// ```
664661 ///
@@ -1168,11 +1165,12 @@ impl CStr {
11681165 /// # Examples
11691166 ///
11701167 /// ```
1171- /// use std::ffi::CString;
1168+ /// use std::ffi::{CStr, CString} ;
11721169 ///
1173- /// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed");
1174- /// let boxed = c_string.into_boxed_c_str();
1175- /// assert_eq!(boxed.into_c_string(), CString::new("foo").expect("CString::new failed"));
1170+ /// let boxed: Box<CStr> = Box::from(c"foo");
1171+ /// let c_string: CString = c"foo".to_owned();
1172+ ///
1173+ /// assert_eq!(boxed.into_c_string(), c_string);
11761174 /// ```
11771175 #[ rustc_allow_incoherent_impl]
11781176 #[ must_use = "`self` will be dropped if the result is not used" ]
0 commit comments