#[non_exhaustive]pub enum Error {
Unsupported {
what: &'static str,
platform: &'static str,
},
PermissionDenied {
what: &'static str,
hint: &'static str,
},
NotFound {
what: &'static str,
source: &'static str,
},
Malformed {
what: &'static str,
source: &'static str,
line: Option<u32>,
},
TooLarge {
what: &'static str,
limit: u64,
},
TooSoon {
elapsed: Duration,
minimum: Duration,
},
Os {
what: &'static str,
call: &'static str,
code: i32,
},
Io {
what: &'static str,
source: Error,
},
InvalidInput {
what: &'static str,
reason: &'static str,
},
AlreadyRunning {
pid: Option<u32>,
lock_file: PathBuf,
},
RunDirUnavailable {
path: PathBuf,
source: Error,
},
OpenFilesTooLow {
have: u64,
need: u64,
},
}Expand description
Everything that can go wrong in sys-lib.
Every variant’s message is one sentence saying what failed, followed by
what to do about it. No variant ever carries file content, registry content,
or identifier values: Error::Malformed names the source (a constant
path) and a line number only.
§Examples
use sys_lib as sys;
match sys::host::name() {
Ok(name) => println!("host {name}"),
Err(e) if e.is_unavailable() => println!("host name unknown here: {e}"),
Err(e) => return Err(e),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Unsupported
This reading does not exist on this platform. Treat the value as unknown.
PermissionDenied
The OS refused (root-only files, a sandbox, SELinux, seccomp).
NotFound
A file or key that should exist does not (a container with a reduced /proc).
Malformed
The OS returned data that does not parse.
Fields
TooLarge
A file, a list, or a caller’s buffer exceeded its budget.
TooSoon
A sampler was asked again before any time passed on the OS clock.
Fields
Os
A system call failed.
Fields
Io
File I/O failed outside the cases above.
InvalidInput
Invalid input from the caller.
AlreadyRunning
The process guard found another copy holding the lock.
Fields
The process guard’s lock directory cannot be created, written, or trusted.
OpenFilesTooLow
The hard open-file limit is below the process guard’s minimum.
Implementations§
Source§impl Error
impl Error
True for the errors that mean “this fact is not available here”, which a
caller usually treats as unknown: Unsupported,
PermissionDenied, and NotFound.
let e = sys_lib::Error::Unsupported { what: "load average", platform: "windows" };
assert!(e.is_unavailable());Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()