Skip to content

Commit 883a241

Browse files
committed
Auto merge of rust-lang#91101 - birkenfeld:io_error_docs, r=Mark-Simulacrum
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.
2 parents cd83a43 + 289eb78 commit 883a241

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/std/src/io/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ impl Error {
392392
/// originate from the OS itself. The `error` argument is an arbitrary
393393
/// payload which will be contained in this [`Error`].
394394
///
395+
/// If no extra payload is required, use the `From` conversion from
396+
/// `ErrorKind`.
397+
///
395398
/// # Examples
396399
///
397400
/// ```
@@ -402,6 +405,9 @@ impl Error {
402405
///
403406
/// // errors can also be created from other errors
404407
/// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
408+
///
409+
/// // creating an error without payload
410+
/// let eof_error = Error::from(ErrorKind::UnexpectedEof);
405411
/// ```
406412
#[stable(feature = "rust1", since = "1.0.0")]
407413
pub fn new<E>(kind: ErrorKind, error: E) -> Error

0 commit comments

Comments
 (0)