2 unstable releases

0.2.0 Mar 8, 2024
0.1.1 Sep 27, 2020
0.1.0 Sep 27, 2020

#396 in Operating systems

Download history 783/week @ 2024-07-26 531/week @ 2024-08-02 417/week @ 2024-08-09 112/week @ 2024-08-16 75/week @ 2024-08-23 100/week @ 2024-08-30 144/week @ 2024-09-06 123/week @ 2024-09-13 106/week @ 2024-09-20 125/week @ 2024-09-27 126/week @ 2024-10-04 122/week @ 2024-10-11 185/week @ 2024-10-18 95/week @ 2024-10-25 90/week @ 2024-11-01 57/week @ 2024-11-08

469 downloads per month
Used in 4 crates (2 directly)

MIT license

24KB
236 lines

Verify

system_error

A library for cross platform system errors.

Take a look at the Documentation for details!


lib.rs:

A library for cross platform system errors.

This library captures the behavior and messaging for errno on unix platforms, GetLastError() on Windows, and kern_return_t on macOS and iOS. Additionally, these Error values can be converted into std::io::Error values.

Examples

On Linux:

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

let os_error = Error::from_raw_os_error(1);
assert_eq!(os_error.kind(), ErrorKind::PermissionDenied);
assert_eq!(
    format!("{}", os_error),
    "Operation not permitted (os error 1)"
);
assert_eq!(
    format!("{:?}", os_error),
    "Error { kind: PermissionDenied, message: \"Operation not permitted (os error 1)\" }"
);

let kern_error = Error::from_raw_kernel_error(8);
assert_eq!(kern_error.kind(), ErrorKind::Other);
assert_eq!(
    format!("{}", kern_error),
    "Unknown error (kernel error 8)"
);
assert_eq!(
    format!("{:?}", kern_error),
    "Error { kind: Other, message: \"Unknown error (kernel error 8)\" }"
);

On macOS:

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

let os_error = Error::from_raw_os_error(1);
assert_eq!(os_error.kind(), ErrorKind::PermissionDenied);
assert_eq!(
    format!("{}", os_error),
    "Operation not permitted (os error 1)"
);
assert_eq!(
    format!("{:?}", os_error),
    "Error { kind: PermissionDenied, message: \"Operation not permitted (os error 1)\" }"
);

let kern_error = Error::from_raw_kernel_error(8);
assert_eq!(kern_error.kind(), ErrorKind::PermissionDenied);
assert_eq!(
    format!("{}", kern_error),
    "(os/kern) no access (kernel error 8)"
);
assert_eq!(
    format!("{:?}", kern_error),
    "Error { kind: PermissionDenied, message: \"(os/kern) no access (kernel error 8)\" }"
);

On Windows:

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

let os_error = Error::from_raw_os_error(5);
assert_eq!(os_error.kind(), ErrorKind::PermissionDenied);
assert_eq!(
    format!("{}", os_error),
    "Access is denied. (os error 5)"
);
assert_eq!(
    format!("{:?}", os_error),
    "Error { kind: PermissionDenied, message: \"Access is denied. (os error 5)\" }"
);

let kern_error = Error::from_raw_kernel_error(8);
assert_eq!(kern_error.kind(), ErrorKind::Other);
assert_eq!(
    format!("{}", kern_error),
    "Unknown error (kernel error 8)"
);
assert_eq!(
    format!("{:?}", kern_error),
    "Error { kind: Other, message: \"Unknown error (kernel error 8)\" }"
);

No runtime deps