2 unstable releases
0.2.0 | Mar 8, 2024 |
---|---|
0.1.1 | Sep 27, 2020 |
0.1.0 |
|
#396 in Operating systems
469 downloads per month
Used in 4 crates
(2 directly)
24KB
236 lines
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)\" }"
);