mmap_rs/
error.rs

1//! This module implements the error type used throughout this crate.
2
3use crate::UnsafeMmapFlags;
4use thiserror::Error;
5
6/// The error type.
7#[derive(Debug, Error)]
8pub enum Error {
9    /// The following set of unsafe flags must be set to call this function.
10    #[error("{0:?} must be set")]
11    UnsafeFlagNeeded(UnsafeMmapFlags),
12
13    /// The size is invalid.
14    #[error("invalid size")]
15    InvalidSize,
16
17    /// The offset is invalid.
18    #[error("invalid offset")]
19    InvalidOffset,
20
21    /// The operation is invalid.
22    #[error("invalid operation")]
23    InvalidOperation,
24
25    /// The memory maps must be adjacent.
26    #[error("the memory maps must be adjacent")]
27    MustBeAdjacent,
28
29    /// The attributes of the memory maps do not match.
30    #[error("the memory maps must share the same attributes")]
31    AttributeMismatch,
32
33    /// The backings of the memory maps do not match.
34    #[error("the memory maps must share the same backing")]
35    BackingMismatch,
36
37    /// Represents [`std::io::Error`].
38    #[error(transparent)]
39    Io(#[from] std::io::Error),
40
41    /// Represents [`std::num::ParseIntError`].
42    #[error(transparent)]
43    ParseInt(#[from] std::num::ParseIntError),
44
45    /// Represents [`std::str::Utf8Error`].
46    #[error(transparent)]
47    Utf8(std::str::Utf8Error),
48
49    #[cfg(unix)]
50    /// Represents [`nix::Error`].
51    #[error(transparent)]
52    Nix(#[from] nix::Error),
53
54    #[cfg(unix)]
55    /// Represents [`sysctl::SysctlError`].
56    #[error(transparent)]
57    Sysctl(#[from] sysctl::SysctlError),
58
59    #[cfg(any(target_os = "macos", target_os = "ios"))]
60    /// The error code returned from the Mach API.
61    #[error("Mach kernel result = {0}")]
62    Mach(libc::c_int),
63
64    #[cfg(target_os = "windows")]
65    /// Represents [`windows::core::Error`].
66    #[error(transparent)]
67    Windows(#[from] windows::core::Error),
68}