swapvec/
error.rs

1/// A collection of all possible errors.
2///
3/// Errors could be divided into write and read
4/// errors, but this makes error handling a bit less
5/// comfortable, so they are united here.
6#[derive(Debug)]
7#[non_exhaustive]
8pub enum SwapVecError {
9    /// The program is missing permissions to create a temporary file
10    MissingPermissions,
11    /// A batch could not be written due to a full disk
12    OutOfDisk,
13    /// A read back batch had a wrong checksum
14    WrongChecksum,
15    /// A batch could not be decompressed correctly.
16    /// This also happens only if the file has been corrupted.
17    Decompression,
18    /// The batch was read back successfully,
19    /// but the serialization failed.
20    ///
21    /// Take a look at the `Serialize` implementation
22    /// of your type `T`.
23    SerializationFailed(bincode::ErrorKind),
24    /// Every other possibility
25    Other(std::io::ErrorKind),
26}
27
28impl From<std::io::Error> for SwapVecError {
29    fn from(_value: std::io::Error) -> Self {
30        match _value.kind() {
31            // TODO https://github.com/rust-lang/rust/issues/86442
32            // std::io::ErrorKind::StorageFull => Self::OutOfDisk,
33            std::io::ErrorKind::PermissionDenied => Self::MissingPermissions,
34            e => Self::Other(e),
35        }
36    }
37}
38
39impl From<Box<bincode::ErrorKind>> for SwapVecError {
40    fn from(value: Box<bincode::ErrorKind>) -> Self {
41        SwapVecError::SerializationFailed(*value)
42    }
43}