bee_storage/system/
health.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Defines a type to represent different health states in which the storage backend can be.
5
6use core::convert::Infallible;
7
8/// Errors related to storage health statuses.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// I/O error happened.
12    #[error("i/o error happened: {0:?}")]
13    Io(#[from] std::io::Error),
14    /// Unknown storage health variant.
15    #[error("unknown storage health variant: {0}")]
16    UnknownHealth(u8),
17}
18
19impl From<Infallible> for Error {
20    fn from(err: Infallible) -> Self {
21        match err {}
22    }
23}
24
25/// Represents different health states for a `StorageBackend`.
26#[repr(u8)]
27#[derive(Debug, Copy, Clone, Eq, PartialEq, packable::Packable)]
28#[packable(unpack_error = Error)]
29#[packable(tag_type = u8, with_error = Error::UnknownHealth)]
30pub enum StorageHealth {
31    /// The storage is in a healthy state.
32    Healthy = 0,
33    /// The storage is running and the health status is idle.
34    Idle = 1,
35    /// The storage has been corrupted.
36    Corrupted = 2,
37}