Struct std::io::Error
[−]
[src]
pub struct Error {
// some fields omitted
}The error type for I/O operations of the Read`Read,`, Write`Write,`, Seek`Seek`, and
associated traits.
Errors mostly originate from the underlying OS, but custom instances of
Error`Errorcan be created with crafted error messages and a particular value ofErrorKind`.
Methods
impl Error
fn new<E>(kind: ErrorKind, error: E) -> Error where E: Into<Box<Error + Send + Sync>>
Creates a new I/O error from a known kind of error as well as an arbitrary error payload.
This function is used to generically create I/O errors which do not
originate from the OS itself. The error`errorargument is an arbitrary payload which will be contained in thisError`.
Examples
fn main() { use std::io::{Error, ErrorKind}; // errors can be created from strings let custom_error = Error::new(ErrorKind::Other, "oh no!"); // errors can also be created from other errors let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); }use std::io::{Error, ErrorKind}; // errors can be created from strings let custom_error = Error::new(ErrorKind::Other, "oh no!"); // errors can also be created from other errors let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
fn last_os_error() -> Error
Returns an error representing the last OS error which occurred.
This function reads the value of errno`errnofor the target platform (e.g.GetLastErroron Windows) and will return a corresponding instance ofError` for the error code.
fn from_raw_os_error(code: i32) -> Error
Creates a new instance of an Error`Error` from a particular OS error code.
fn raw_os_error(&self) -> Option<i32>
Returns the OS error that this error represents (if any).
If this Error`Errorwas constructed vialast_os_erroror` or
from_raw_os_error, then this function will return Some`Some, otherwise it will returnNone`.
fn get_ref(&self) -> Option<&Error + Send + Sync + 'static>
Returns a reference to the inner error wrapped by this error (if any).
If this Error`Errorwas constructed vianewthen this function will returnSome, otherwise it will returnNone`.
fn get_mut(&mut self) -> Option<&mut Error + Send + Sync + 'static>
Returns a mutable reference to the inner error wrapped by this error (if any).
If this Error`Errorwas constructed vianewthen this function will returnSome, otherwise it will returnNone`.
fn into_inner(self) -> Option<Box<Error + Send + Sync>>
Consumes the Error`Error`, returning its inner error (if any).
If this Error`Errorwas constructed vianewthen this function will returnSome, otherwise it will returnNone`.
fn kind(&self) -> ErrorKind
Returns the corresponding ErrorKind for this error.