Mention std::io::Error::from(ErrorKind) in Error::new() docs

This conversion is not very discoverable for the cases
where an error is required without extra payload.
This commit is contained in:
Georg Brandl 2021-11-21 09:00:13 +01:00
parent 3d789740b0
commit 289eb786d4

View File

@ -392,6 +392,9 @@ impl Error {
/// originate from the OS itself. The `error` argument is an arbitrary /// originate from the OS itself. The `error` argument is an arbitrary
/// payload which will be contained in this [`Error`]. /// payload which will be contained in this [`Error`].
/// ///
/// If no extra payload is required, use the `From` conversion from
/// `ErrorKind`.
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -402,6 +405,9 @@ impl Error {
/// ///
/// // errors can also be created from other errors /// // errors can also be created from other errors
/// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
///
/// // creating an error without payload
/// let eof_error = Error::from(ErrorKind::UnexpectedEof);
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn new<E>(kind: ErrorKind, error: E) -> Error pub fn new<E>(kind: ErrorKind, error: E) -> Error