lsm_tree/
version.rs

1// Copyright (c) 2024-present, fjall-rs
2// This source code is licensed under both the Apache 2.0 and MIT License
3// (found in the LICENSE-* files in the repository)
4
5/// Disk format version
6#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7pub enum Version {
8    /// Version for 1.x.x releases
9    V1,
10
11    /// Version for 2.x.x releases
12    V2,
13}
14
15impl std::fmt::Display for Version {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        write!(f, "{}", u8::from(*self))
18    }
19}
20
21impl From<Version> for u8 {
22    fn from(value: Version) -> Self {
23        match value {
24            Version::V1 => 1,
25            Version::V2 => 2,
26        }
27    }
28}
29
30impl TryFrom<u8> for Version {
31    type Error = ();
32
33    fn try_from(value: u8) -> Result<Self, Self::Error> {
34        match value {
35            1 => Ok(Self::V1),
36            2 => Ok(Self::V2),
37            _ => Err(()),
38        }
39    }
40}