remove dependency on num
This commit is contained in:
parent
3b9586a69e
commit
62ca9037b6
11 changed files with 124 additions and 314 deletions
41
src/compression_code.rs
Normal file
41
src/compression_code.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use CompressionCode::*;
|
||||
|
||||
/// Specifies the kind of compression to use. Availability depends on features.
|
||||
#[repr(u16)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum CompressionCode {
|
||||
Uncompressed = 0x0,
|
||||
#[cfg(feature = "compression-gz")]
|
||||
Gz = 0x677a,
|
||||
#[cfg(feature = "compression-bz")]
|
||||
Bz = 0x627a,
|
||||
#[cfg(feature = "compression-lz")]
|
||||
Lz = 0x6c7a,
|
||||
#[cfg(feature = "compression-zs")]
|
||||
Zs = 0x7a73,
|
||||
}
|
||||
|
||||
impl Into<u16> for CompressionCode {
|
||||
fn into(self) -> u16 {
|
||||
self as u16
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u16> for CompressionCode {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: u16) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
value if value == Uncompressed as u16 => Ok(Uncompressed),
|
||||
#[cfg(feature = "compression-gz")]
|
||||
value if value == Gz as u16 => Ok(Gz),
|
||||
#[cfg(feature = "compression-bz")]
|
||||
value if value == Bz as u16 => Ok(Bz),
|
||||
#[cfg(feature = "compression-lz")]
|
||||
value if value == Lz as u16 => Ok(Lz),
|
||||
#[cfg(feature = "compression-zs")]
|
||||
value if value == Zs as u16 => Ok(Zs),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue