@@ -511,13 +511,8 @@ impl CStr {
511
511
/// # Examples
512
512
///
513
513
/// ```
514
- /// use std::ffi::CStr;
515
- ///
516
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0").unwrap();
517
- /// assert_eq!(cstr.count_bytes(), 3);
518
- ///
519
- /// let cstr = CStr::from_bytes_with_nul(b"\0").unwrap();
520
- /// assert_eq!(cstr.count_bytes(), 0);
514
+ /// assert_eq!(c"foo".count_bytes(), 3);
515
+ /// assert_eq!(c"".count_bytes(), 0);
521
516
/// ```
522
517
#[ inline]
523
518
#[ must_use]
@@ -533,19 +528,8 @@ impl CStr {
533
528
/// # Examples
534
529
///
535
530
/// ```
536
- /// use std::ffi::CStr;
537
- /// # use std::ffi::FromBytesWithNulError;
538
- ///
539
- /// # fn main() { test().unwrap(); }
540
- /// # fn test() -> Result<(), FromBytesWithNulError> {
541
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0")?;
542
- /// assert!(!cstr.is_empty());
543
- ///
544
- /// let empty_cstr = CStr::from_bytes_with_nul(b"\0")?;
545
- /// assert!(empty_cstr.is_empty());
531
+ /// assert!(!c"foo".is_empty());
546
532
/// assert!(c"".is_empty());
547
- /// # Ok(())
548
- /// # }
549
533
/// ```
550
534
#[ inline]
551
535
#[ stable( feature = "cstr_is_empty" , since = "1.71.0" ) ]
@@ -569,10 +553,7 @@ impl CStr {
569
553
/// # Examples
570
554
///
571
555
/// ```
572
- /// use std::ffi::CStr;
573
- ///
574
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
575
- /// assert_eq!(cstr.to_bytes(), b"foo");
556
+ /// assert_eq!(c"foo".to_bytes(), b"foo");
576
557
/// ```
577
558
#[ inline]
578
559
#[ must_use = "this returns the result of the operation, \
@@ -598,10 +579,7 @@ impl CStr {
598
579
/// # Examples
599
580
///
600
581
/// ```
601
- /// use std::ffi::CStr;
602
- ///
603
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
604
- /// assert_eq!(cstr.to_bytes_with_nul(), b"foo\0");
582
+ /// assert_eq!(c"foo".to_bytes_with_nul(), b"foo\0");
605
583
/// ```
606
584
#[ inline]
607
585
#[ must_use = "this returns the result of the operation, \
@@ -623,10 +601,8 @@ impl CStr {
623
601
///
624
602
/// ```
625
603
/// #![feature(cstr_bytes)]
626
- /// use std::ffi::CStr;
627
604
///
628
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
629
- /// assert!(cstr.bytes().eq(*b"foo"));
605
+ /// assert!(c"foo".bytes().eq(*b"foo"));
630
606
/// ```
631
607
#[ inline]
632
608
#[ unstable( feature = "cstr_bytes" , issue = "112115" ) ]
@@ -645,10 +621,7 @@ impl CStr {
645
621
/// # Examples
646
622
///
647
623
/// ```
648
- /// use std::ffi::CStr;
649
- ///
650
- /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
651
- /// assert_eq!(cstr.to_str(), Ok("foo"));
624
+ /// assert_eq!(c"foo".to_str(), Ok("foo"));
652
625
/// ```
653
626
#[ stable( feature = "cstr_to_str" , since = "1.4.0" ) ]
654
627
#[ rustc_const_stable( feature = "const_cstr_methods" , since = "1.72.0" ) ]
0 commit comments