Skip to content

Commit 3c5e18f

Browse files
Point from the error structs back to the method that created them, like in iterators
1 parent 2cb2a06 commit 3c5e18f

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,13 @@ pub struct CStr {
208208
}
209209

210210
/// An error returned from [`CString::new`] to indicate that a nul byte was found
211-
/// in the vector provided.
211+
/// in the vector provided. While Rust strings may contain nul bytes in the middle,
212+
/// C strings can't, as that byte would effectively truncate the string.
212213
///
214+
/// This `struct` is created by the [`new`][`CString::new`] method on
215+
/// [`CString`]. See its documentation for more.
216+
///
217+
/// [`CString`]: struct.CString.html
213218
/// [`CString::new`]: struct.CString.html#method.new
214219
///
215220
/// # Examples
@@ -225,9 +230,15 @@ pub struct NulError(usize, Vec<u8>);
225230

226231
/// An error returned from [`CStr::from_bytes_with_nul`] to indicate
227232
/// that a nul byte was found too early in the slice provided, or one
228-
/// wasn't found at all. The slice used to create a `CStr` must have one
229-
/// and only one nul byte at the end of the slice.
233+
/// wasn't found at all for the nul terminator. The slice used to
234+
/// create a `CStr` must have one and only one nul byte at the end of
235+
/// the slice.
236+
///
237+
/// This `struct` is created by the
238+
/// [`from_bytes_with_nul`][`CStr::from_bytes_with_nul`] method on
239+
/// [`CStr`]. See its documentation for more.
230240
///
241+
/// [`CStr`]: struct.CStr.html
231242
/// [`CStr::from_bytes_with_nul`]: struct.CStr.html#method.from_bytes_with_nul
232243
///
233244
/// # Examples
@@ -262,9 +273,17 @@ impl FromBytesWithNulError {
262273
}
263274
}
264275

265-
/// An error returned from [`CString::into_string`] to indicate that a UTF-8 error
266-
/// was encountered during the conversion.
276+
/// An error returned from [`CString::into_string`] to indicate that a
277+
/// UTF-8 error was encountered during the conversion. `CString` is
278+
/// just a wrapper over a buffer of bytes with a nul terminator;
279+
/// [`into_string`][`CString::into_string`] performs UTF-8 validation
280+
/// and may return this error.
281+
///
282+
/// This `struct` is created by the
283+
/// [`into_string`][`CString::into_string`] method on [`CString`]. See
284+
/// its documentation for more.
267285
///
286+
/// [`CString`]: struct.CString.html
268287
/// [`CString::into_string`]: struct.CString.html#method.into_string
269288
#[derive(Clone, PartialEq, Eq, Debug)]
270289
#[stable(feature = "cstring_into", since = "1.7.0")]

0 commit comments

Comments
 (0)