#mach #error #cross-platform

system_error

A library for cross platform system errors

2 unstable releases

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

#6 in #mach

Download history 886/week @ 2024-06-18 759/week @ 2024-06-25 714/week @ 2024-07-02 700/week @ 2024-07-09 719/week @ 2024-07-16 986/week @ 2024-07-23 681/week @ 2024-07-30 540/week @ 2024-08-06 221/week @ 2024-08-13 80/week @ 2024-08-20 117/week @ 2024-08-27 108/week @ 2024-09-03 140/week @ 2024-09-10 88/week @ 2024-09-17 141/week @ 2024-09-24 83/week @ 2024-10-01

520 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