[][src]Struct system_error::Error

pub struct Error(_);

An error type for cross platform system-level errors.

This type captures the behavior and error message for errno on unix platforms, GetLastError() on Windows, and kern_return_t on macOS and iOS.

Implementations

impl Error[src]

pub fn last_os_error() -> Self[src]

Returns an error representing the last OS error which occurred.

This function reads the value of errno for the target platform (e.g. GetLastError on Windows) and will return a corresponding instance of Error for the error code.

Examples

use system_error::Error;

println!("last OS error: {:?}", Error::last_os_error());

pub fn from_raw_os_error(code: OsCode) -> Self[src]

Creates a new instance of an Error from a particular OS error code.

Examples

On Linux:

use system_error::Error;
use std::io;

let error = Error::from_raw_os_error(22);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);

On Windows:

use system_error::Error;
use std::io;

let error = Error::from_raw_os_error(10022);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);

pub fn from_raw_kernel_error(code: KernelCode) -> Self[src]

Creates a new instance of an Error from a particular kernel error code.

Examples

On macOS:

use system_error::Error;
use std::io;

let error = Error::from_raw_kernel_error(4);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);

On Linux:

use system_error::Error;
use std::io;

let error = Error::from_raw_kernel_error(4);
assert_eq!(error.kind(), io::ErrorKind::Other);

pub fn kind(&self) -> ErrorKind[src]

Returns the corresponding ErrorKind for this error.

Examples

use system_error::Error;
use std::io;

assert_eq!(Error::last_os_error().kind(), io::ErrorKind::Other);
assert_eq!(Error::from_raw_os_error(1).kind(), io::ErrorKind::PermissionDenied);

pub fn raw_os_error(&self) -> Option<i32>[src]

Returns the OS error that this error represents (if any).

If this Error was constructed via last_os_error or from_raw_os_error, then this function will return Some, otherwise it will return None.

Examples

use system_error::Error;

fn print_os_error(err: &Error) {
    if let Some(raw_os_err) = err.raw_os_error() {
        println!("raw OS error: {:?}", raw_os_err);
    } else {
        println!("Not an OS error");
    }
}

let os_err = Error::last_os_error();
let kern_err = Error::from_raw_kernel_error(8);

// Will print "raw OS error: ...".
print_os_error(&os_err);
// Will print "Not an OS error".
print_os_error(&kern_err);

assert!(os_err.raw_os_error().is_some());
assert_eq!(kern_err.raw_os_error(), None);

pub fn raw_kernel_error(&self) -> Option<i32>[src]

Returns the kernel error that this error represents (if any).

If this Error was constructed via from_raw_kernel_error then this function will return Some, otherwise it will return None.

Examples

use system_error::Error;

fn print_kernel_error(err: &Error) {
    if let Some(raw_kernel_err) = err.raw_kernel_error() {
        println!("raw kernel error: {:?}", raw_kernel_err);
    } else {
        println!("Not an kernel error");
    }
}

let kern_err = Error::from_raw_kernel_error(8);
let os_err = Error::last_os_error();

// Will print "raw kernel error: 8".
print_kernel_error(&kern_err);
// Will print "Not an kernel error".
print_kernel_error(&os_err);

assert_eq!(kern_err.raw_kernel_error(), Some(8));
assert_eq!(os_err.raw_kernel_error(), None);

Trait Implementations

impl Debug for Error[src]

impl Display for Error[src]

impl Error for Error[src]

impl Into<Error> for Error[src]

impl TryFrom<Error> for Error[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl UnwindSafe for Error

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.