File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -708,6 +708,24 @@ impl CStr {
708
708
/// let cstr = CStr::from_bytes_with_nul(b"hello\0");
709
709
/// assert!(cstr.is_ok());
710
710
/// ```
711
+ ///
712
+ /// Creating a `CStr` without a trailing nul byte is an error:
713
+ ///
714
+ /// ```
715
+ /// use std::ffi::CStr;
716
+ ///
717
+ /// let c_str = CStr::from_bytes_with_nul(b"hello");
718
+ /// assert!(c_str.is_err());
719
+ /// ```
720
+ ///
721
+ /// Creating a `CStr` with an interior nul byte is an error:
722
+ ///
723
+ /// ```
724
+ /// use std::ffi::CStr;
725
+ ///
726
+ /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
727
+ /// assert!(c_str.is_err());
728
+ /// ```
711
729
#[ stable( feature = "cstr_from_bytes" , since = "1.10.0" ) ]
712
730
pub fn from_bytes_with_nul ( bytes : & [ u8 ] )
713
731
-> Result < & CStr , FromBytesWithNulError > {
You can’t perform that action at this time.
0 commit comments