bee_storage/system/
mod.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Types related to the state of the storage itself.
5
6mod health;
7mod version;
8
9use core::convert::Infallible;
10
11pub use self::{
12    health::{Error as StorageHealthError, StorageHealth},
13    version::StorageVersion,
14};
15
16/// Key used to store the system version.
17pub const SYSTEM_VERSION_KEY: u8 = 0;
18/// Key used to store the system health.
19pub const SYSTEM_HEALTH_KEY: u8 = 1;
20
21/// Errors to be raised if packing/unpacking `System` fails.
22#[derive(Debug, thiserror::Error)]
23pub enum Error {
24    /// I/O error.
25    #[error("i/o error happened: {0}")]
26    Io(#[from] std::io::Error),
27    /// Packing/unpacking the `System::Health` variant failed.
28    #[error("storage health error: {0}")]
29    Health(#[from] StorageHealthError),
30    /// Found an invalid key while unpacking a `System` value.
31    #[error("unknown system key: {0}")]
32    UnknownSystemKey(u8),
33}
34
35impl From<Infallible> for Error {
36    fn from(err: Infallible) -> Self {
37        match err {}
38    }
39}
40
41/// System-related information.
42#[derive(Debug, Copy, Clone, Eq, PartialEq, packable::Packable)]
43#[packable(unpack_error = Error)]
44#[packable(tag_type = u8, with_error = Error::UnknownSystemKey)]
45pub enum System {
46    /// The current version of the storage.
47    #[packable(tag = SYSTEM_VERSION_KEY)]
48    Version(StorageVersion),
49    /// The health status of the storage.
50    #[packable(tag = SYSTEM_HEALTH_KEY)]
51    Health(StorageHealth),
52}