#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "adaptive")]
mod adaptive;
mod decode;
mod encode;
mod error;
#[cfg(feature = "adaptive")]
#[cfg_attr(docsrs, doc(cfg(feature = "adaptive")))]
pub use adaptive::{Adaptive, Choice, Stat};
pub use decode::{decode, decode_limit, decode_owned, decode_owned_limit};
pub use encode::{Encoded, encode, encode_into, encode_owned};
pub use error::{Error, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum Type {
Raw = 0,
Zstd = 1,
}
impl TryFrom<u8> for Type {
type Error = Error;
#[inline]
fn try_from(tag: u8) -> Result<Self> {
match tag {
0 => Ok(Self::Raw),
1 => Ok(Self::Zstd),
other => Err(Error::InvalidType(other)),
}
}
}
impl From<Type> for u8 {
#[inline]
fn from(value: Type) -> Self {
value as Self
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(i32)]
pub enum Level {
Fastest = 1,
Fast = 3,
#[default]
Balanced = 6,
Strong = 9,
Best = 19,
}
impl Level {
pub const ALL: [Self; 5] = [
Self::Fastest,
Self::Fast,
Self::Balanced,
Self::Strong,
Self::Best,
];
#[must_use]
#[inline]
pub const fn get(self) -> i32 {
self as i32
}
#[cfg(feature = "adaptive")]
#[inline]
pub(crate) const fn index(self) -> usize {
match self {
Self::Fastest => 0,
Self::Fast => 1,
Self::Balanced => 2,
Self::Strong => 3,
Self::Best => 4,
}
}
}
#[cfg(feature = "adaptive")]
const _: () = {
let mut i = 0;
while i < Level::ALL.len() {
assert!(Level::ALL[i].index() == i);
i += 1;
}
};
impl From<Level> for i32 {
#[inline]
fn from(value: Level) -> Self {
value.get()
}
}