Skip to main content

rustolio_db/
error.rs

1//
2// SPDX-License-Identifier: MPL-2.0
3//
4// Copyright (c) 2026 Tobias Binnewies. All rights reserved.
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9//
10
11use std::io;
12
13pub type Result<T> = std::result::Result<T, Error>;
14
15#[derive(Debug)]
16pub enum Error {
17    FileError(io::Error),
18    EncodingError(rustolio_utils::Error),
19    StoreClosed,
20    NotAllowed,
21}
22
23impl From<Error> for String {
24    fn from(val: Error) -> Self {
25        val.to_string()
26    }
27}
28
29impl std::fmt::Display for Error {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        write!(f, "{self:?}")
32    }
33}
34
35impl std::error::Error for Error {
36    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37        match self {
38            Self::FileError(e) => Some(e),
39            Self::EncodingError(e) => Some(e),
40            Self::StoreClosed | Self::NotAllowed => None,
41        }
42    }
43}