mmap_rs_with_map_from_existing/
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    /// The memory maps must be adjacent.
38    #[error("trying to create Mmap from existing address but the address was not specified in MmapOptions")]
39    MissingAddressForExistingMap,
40
41    /// Represents [`std::io::Error`].
42    #[error(transparent)]
43    Io(#[from] std::io::Error),
44
45    /// Represents [`std::num::ParseIntError`].
46    #[error(transparent)]
47    ParseInt(#[from] std::num::ParseIntError),
48
49    /// Represents [`std::str::Utf8Error`].
50    #[error(transparent)]
51    Utf8(std::str::Utf8Error),
52
53    #[cfg(unix)]
54    /// Represents [`nix::Error`].
55    #[error(transparent)]
56    Nix(#[from] nix::Error),
57
58    #[cfg(unix)]
59    /// Represents [`sysctl::SysctlError`].
60    #[error(transparent)]
61    Sysctl(#[from] sysctl::SysctlError),
62
63    #[cfg(any(target_os = "macos", target_os = "ios"))]
64    /// The error code returned from the Mach API.
65    #[error("Mach kernel result = {0}")]
66    Mach(libc::c_int),
67
68    #[cfg(target_os = "windows")]
69    /// Represents [`windows::core::Error`].
70    #[error(transparent)]
71    Windows(#[from] windows::core::Error),
72}