Document how last_os_error should be used

This commit is contained in:
Chris Denton 2021-12-02 17:51:44 +00:00
parent 18bb8c61a9
commit 6df44a389c
No known key found for this signature in database
GPG key ID: 713472F2F45627DE

View file

@ -440,12 +440,18 @@ impl Error {
/// `GetLastError` on Windows) and will return a corresponding instance of
/// [`Error`] for the error code.
///
/// This should be called immediately after a call to a platform function,
/// otherwise the state of the error value is indeterminate. In particular,
/// other standard library functions may call platform functions that may
/// (or may not) reset the error value even if they succeed.
///
/// # Examples
///
/// ```
/// use std::io::Error;
///
/// println!("last OS error: {:?}", Error::last_os_error());
/// let os_error = Error::last_os_error();
/// println!("last OS error: {:?}", os_error);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]