Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unsupported

This reading does not exist on this platform. Treat the value as unknown.

Fields

§what: &'static str

The reading.

§platform: &'static str

The platform that lacks it.

§

PermissionDenied

The OS refused (root-only files, a sandbox, SELinux, seccomp).

Fields

§what: &'static str

The reading.

§hint: &'static str

The permission that would allow it.

§

NotFound

A file or key that should exist does not (a container with a reduced /proc).

Fields

§what: &'static str

The reading.

§source: &'static str

The file, key, or call that was missing.

§

Malformed

The OS returned data that does not parse.

Fields

§what: &'static str

The reading.

§source: &'static str

The file, key, or call the data came from.

§line: Option<u32>

The line, when the data is line-based.

§

TooLarge

A file, a list, or a caller’s buffer exceeded its budget.

Fields

§what: &'static str

The reading.

§limit: u64

The budget that was exceeded.

§

TooSoon

A sampler was asked again before any time passed on the OS clock.

Fields

§elapsed: Duration

The time since the previous sample.

§minimum: Duration

The shortest interval that gives a meaningful value.

§

Os

A system call failed.

Fields

§what: &'static str

The reading.

§call: &'static str

The call that failed.

§code: i32

The OS error code (errno, a Win32 error, an NTSTATUS, a kern_return_t).

§

Io

File I/O failed outside the cases above.

Fields

§what: &'static str

The reading.

§source: Error

The underlying error.

§

InvalidInput

Invalid input from the caller.

Fields

§what: &'static str

The input.

§reason: &'static str

The rule it broke.

§

AlreadyRunning

The process guard found another copy holding the lock.

Fields

§pid: Option<u32>

The other copy’s process id, when its pid file is readable.

§lock_file: PathBuf

The lock file.

§

RunDirUnavailable

The process guard’s lock directory cannot be created, written, or trusted.

Fields

§path: PathBuf

The directory.

§source: Error

Why, as an I/O error (the kind and a message naming the fix).

§

OpenFilesTooLow

The hard open-file limit is below the process guard’s minimum.

Fields

§have: u64

The hard limit the process has.

§need: u64

The minimum the guard was asked for.

Implementations§

Source§

impl Error

Source

pub fn is_unavailable(&self) -> bool

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 Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.