1#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7pub enum Version {
8 V1,
10
11 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}