mmap_io/
errors.rs

1//! Crate-specific error types for mmap-io.
2
3use std::io;
4use thiserror::Error;
5
6/// Result alias for mmap-io operations.
7pub type Result<T> = std::result::Result<T, MmapIoError>;
8
9/// Error type covering filesystem, mapping, bounds, and concurrency issues.
10#[derive(Debug, Error)]
11pub enum MmapIoError {
12    /// Wrapper for `std::io::Error`.
13    #[error("I/O error: {0}")]
14    Io(#[from] io::Error),
15
16    /// Error returned when attempting an operation in an incompatible mode.
17    #[error("invalid access mode: {0}")]
18    InvalidMode(&'static str),
19
20    /// Error when a requested offset/length pair is out of bounds.
21    #[error("range out of bounds: offset={offset}, len={len}, total={total}")]
22    OutOfBounds {
23        /// Requested offset.
24        offset: u64,
25        /// Requested length.
26        len: u64,
27        /// Total size of the mapped file.
28        total: u64,
29    },
30
31    /// Error when a flush operation fails.
32    #[error("flush failed: {0}")]
33    FlushFailed(String),
34
35    /// Error when resizing is not allowed or fails.
36    #[error("resize failed: {0}")]
37    ResizeFailed(String),
38
39    /// Error when memory advise fails.
40    #[error("advice failed: {0}")]
41    AdviceFailed(String),
42
43    /// Error when lock operation fails.
44    #[error("lock failed: {0}")]
45    LockFailed(String),
46
47    /// Error when unlock operation fails.
48    #[error("unlock failed: {0}")]
49    UnlockFailed(String),
50
51    /// Error when alignment is required for atomic memory views.
52    #[error("atomic alignment error: required={required}, offset={offset}")]
53    Misaligned {
54        /// Required alignment in bytes.
55        required: u64,
56        /// Provided offset in bytes.
57        offset: u64,
58    },
59
60    /// Error when starting or running a watcher fails.
61    #[error("watch failed: {0}")]
62    WatchFailed(String),
63}