reflex/storage/mmap/
error.rs

1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5/// Errors returned by mmap operations.
6pub enum MmapError {
7    /// Underlying IO error.
8    #[error("I/O error: {0}")]
9    Io(#[from] io::Error),
10
11    /// File was smaller than required.
12    #[error("File size {actual} is smaller than minimum {expected}")]
13    FileTooSmall {
14        /// Expected minimum size (bytes).
15        expected: usize,
16        /// Actual size (bytes).
17        actual: usize,
18    },
19
20    /// Cannot map an empty file.
21    #[error("Cannot mmap empty file")]
22    EmptyFile,
23
24    /// `rkyv` validation failed.
25    #[error("rkyv validation failed: {0}")]
26    ValidationFailed(String),
27
28    /// The requested offset was not aligned for `rkyv` access.
29    #[error("Data at offset {offset} is not aligned to {alignment} bytes")]
30    AlignmentError {
31        /// Requested offset (bytes).
32        offset: usize,
33        /// Required alignment (bytes).
34        alignment: usize,
35    },
36
37    /// File resize failed (read-only map, invalid size, or OS error).
38    #[error("Failed to resize file: {0}")]
39    ResizeFailed(String),
40}
41
42/// Convenience result type for mmap operations.
43pub type MmapResult<T> = Result<T, MmapError>;