Skip to content

Commit 1da327f

Browse files
committed
Updated expect messages for CString struct and method documentation
1 parent 29e68fe commit 1da327f

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

library/alloc/src/ffi/c_str.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use crate::vec::Vec;
8484
///
8585
/// // We are certain that our string doesn't have 0 bytes in the middle,
8686
/// // so we can .expect()
87-
/// let c_to_print = CString::new("Hello, world!").expect("CString::new failed");
87+
/// let c_to_print = CString::new("Hello, world!").expect("the provided string should not have a nul byte");
8888
/// unsafe {
8989
/// my_printer(c_to_print.as_ptr());
9090
/// }
@@ -242,7 +242,7 @@ impl CString {
242242
///
243243
/// extern "C" { fn puts(s: *const c_char); }
244244
///
245-
/// let to_print = CString::new("Hello!").expect("CString::new failed");
245+
/// let to_print = CString::new("Hello!").expect("the provided string should not have a nul byte");
246246
/// unsafe {
247247
/// puts(to_print.as_ptr());
248248
/// }
@@ -466,12 +466,12 @@ impl CString {
466466
/// use std::ffi::CString;
467467
///
468468
/// let valid_utf8 = vec![b'f', b'o', b'o'];
469-
/// let cstring = CString::new(valid_utf8).expect("CString::new failed");
469+
/// let cstring = CString::new(valid_utf8).expect("the provided vector of bytes should not contain a nul byte");
470470
/// assert_eq!(cstring.into_string().expect("into_string() call failed"), "foo");
471471
///
472472
/// let invalid_utf8 = vec![b'f', 0xff, b'o', b'o'];
473-
/// let cstring = CString::new(invalid_utf8).expect("CString::new failed");
474-
/// let err = cstring.into_string().err().expect("into_string().err() failed");
473+
/// let cstring = CString::new(invalid_utf8).expect("the provided vector of bytes should not contain a nul byte");
474+
/// let err = cstring.into_string().err().expect("the CString should be invalid utf8 format");
475475
/// assert_eq!(err.utf8_error().valid_up_to(), 1);
476476
/// ```
477477
#[stable(feature = "cstring_into", since = "1.7.0")]
@@ -577,7 +577,7 @@ impl CString {
577577
/// let c_string = CString::from(c"foo");
578578
/// let cstr = c_string.as_c_str();
579579
/// assert_eq!(cstr,
580-
/// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
580+
/// CStr::from_bytes_with_nul(b"foo\0").expect("the provided byte slice should have one nul byte and only at the last index"));
581581
/// ```
582582
#[inline]
583583
#[must_use]
@@ -660,7 +660,7 @@ impl CString {
660660
/// use std::ffi::CString;
661661
/// assert_eq!(
662662
/// CString::from_vec_with_nul(b"abc\0".to_vec())
663-
/// .expect("CString::from_vec_with_nul failed"),
663+
/// .expect("the provided vector of bytes should have one nul byte and only at the last index"),
664664
/// c"abc".to_owned()
665665
/// );
666666
/// ```

0 commit comments

Comments
 (0)