region/
error.rs

1//! Error types and utilities.
2
3use std::error::Error as StdError;
4use std::{fmt, io};
5
6/// The result type used by this library.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// A collection of possible errors.
10#[derive(Debug)]
11pub enum Error {
12  /// The queried memory is unmapped.
13  ///
14  /// This does not necessarily mean that the memory region is available for
15  /// allocation. Besides OS-specific semantics, queried addresses outside of a
16  /// process' adress range are also identified as unmapped regions.
17  UnmappedRegion,
18  /// A supplied parameter is invalid.
19  InvalidParameter(&'static str),
20  /// A procfs region could not be parsed.
21  ProcfsInput(String),
22  /// A system call failed.
23  SystemCall(io::Error),
24  /// A macOS kernel call failed
25  MachCall(libc::c_int),
26}
27
28impl fmt::Display for Error {
29  #[inline]
30  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31    match self {
32      Error::UnmappedRegion => write!(f, "Queried memory is unmapped"),
33      Error::InvalidParameter(param) => write!(f, "Invalid parameter value: {}", param),
34      Error::ProcfsInput(ref input) => write!(f, "Invalid procfs input: {}", input),
35      Error::SystemCall(ref error) => write!(f, "System call failed: {}", error),
36      Error::MachCall(code) => write!(f, "macOS kernel call failed: {}", code),
37    }
38  }
39}
40
41impl StdError for Error {}