pub struct Error { /* private fields */ }Expand description
Implementations§
Source§impl Error
impl Error
Sourcepub fn new<E>(kind: ErrorKind, error: E) -> Error
pub fn new<E>(kind: ErrorKind, error: E) -> Error
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 argument is an arbitrary
payload which will be contained in this Error.
§Examples
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);Sourcepub fn from_raw_os_error(code: i32) -> Error
pub fn from_raw_os_error(code: i32) -> Error
Creates a new instance of an Error from a particular OS error code.
§Examples
On Linux:
use std::io;
let error = io::Error::from_raw_os_error(22);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);On Windows:
use std::io;
let error = io::Error::from_raw_os_error(10022);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);Sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
Returns the corresponding ErrorKind for this error.
§Examples
use std::io::{Error, ErrorKind};
fn print_error(err: Error) {
println!("{:?}", err.kind());
}
fn main() {
// Will print "No inner error".
print_error(Error::last_os_error());
// Will print "Inner error: ...".
print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
}pub fn last_os_error() -> Error
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more