use crate::FloatCode;
use crate::IntCode;
use crate::MAX_CASCADE;
use crate::StringCode;
#[derive(Debug, Clone, Copy, Default)]
pub struct Excludes<'a> {
pub int: &'a [IntCode],
pub float: &'a [FloatCode],
pub string: &'a [StringCode],
}
impl<'a> Excludes<'a> {
pub const fn none() -> Self {
Self {
int: &[],
float: &[],
string: &[],
}
}
pub const fn int_only(int: &'a [IntCode]) -> Self {
Self {
int,
float: &[],
string: &[],
}
}
pub const fn float_only(float: &'a [FloatCode]) -> Self {
Self {
int: &[],
float,
string: &[],
}
}
pub const fn string_only(string: &'a [StringCode]) -> Self {
Self {
int: &[],
float: &[],
string,
}
}
}
impl<'a> From<&'a [IntCode]> for Excludes<'a> {
fn from(int: &'a [IntCode]) -> Self {
Self::int_only(int)
}
}
impl<'a, const N: usize> From<&'a [IntCode; N]> for Excludes<'a> {
fn from(int: &'a [IntCode; N]) -> Self {
Self::int_only(int)
}
}
impl<'a> From<&'a [FloatCode]> for Excludes<'a> {
fn from(float: &'a [FloatCode]) -> Self {
Self::float_only(float)
}
}
impl<'a, const N: usize> From<&'a [FloatCode; N]> for Excludes<'a> {
fn from(float: &'a [FloatCode; N]) -> Self {
Self::float_only(float)
}
}
impl<'a> From<&'a [StringCode]> for Excludes<'a> {
fn from(string: &'a [StringCode]) -> Self {
Self::string_only(string)
}
}
impl<'a, const N: usize> From<&'a [StringCode; N]> for Excludes<'a> {
fn from(string: &'a [StringCode; N]) -> Self {
Self::string_only(string)
}
}
#[derive(Debug, Clone, Copy)]
pub struct CompressorContext {
pub is_sample: bool,
pub allowed_cascading: usize,
}
impl Default for CompressorContext {
fn default() -> Self {
Self {
is_sample: false,
allowed_cascading: MAX_CASCADE,
}
}
}
impl CompressorContext {
pub fn descend(self) -> Self {
Self {
allowed_cascading: self.allowed_cascading.saturating_sub(1),
..self
}
}
pub fn as_sample(self) -> Self {
Self {
is_sample: true,
..self
}
}
}