#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
pub enum CompressionAlgo {
None = 0,
Lz4 = 1,
Zstd = 2,
Custom = 3,
}
impl TryFrom<u8> for CompressionAlgo {
type Error = u8;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::None),
1 => Ok(Self::Lz4),
2 => Ok(Self::Zstd),
3 => Ok(Self::Custom),
other => Err(other),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn round_trip() {
for raw in 0..=3u8 {
let algo = CompressionAlgo::try_from(raw).unwrap();
assert_eq!(algo as u8, raw);
}
}
#[test]
fn invalid_value() {
assert_eq!(CompressionAlgo::try_from(4), Err(4));
}
}