pub struct Error(/* private fields */);
Expand description
Wrapper over errno
.
The error number is an integer number set by system calls and some libc functions in case of error.
Implementations§
source§impl Error
impl Error
sourcepub fn last() -> Error
pub fn last() -> Error
Returns the last occurred errno
wrapped in an Error
.
Calling Error::last()
is the equivalent of using
errno
in C/C++.
The result of this function only has meaning after a libc call or syscall
where errno
was set.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::errno::Error;
// Reading from a file without permissions returns an error.
let mut path = temp_dir();
path.push("test");
let mut file = File::create(path).unwrap();
let mut buf: Vec<u8> = Vec::new();
assert!(file.read_to_end(&mut buf).is_err());
// Retrieve the error number of the previous operation using `Error::last()`:
let read_err = Error::last();
#[cfg(unix)]
assert_eq!(read_err, Error::new(libc::EBADF));
#[cfg(not(unix))]
assert_eq!(read_err, Error::new(libc::EIO));
Trait Implementations§
source§impl Error for Error
impl Error for Error
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
impl Copy for Error
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)