Remove TryFrom for FilterStrategy

This commit is contained in:
Andrew 2025-09-04 09:21:29 +12:00
parent 654552cf73
commit 8d53e52408
2 changed files with 13 additions and 21 deletions

View file

@ -41,22 +41,6 @@ impl Display for FilterStrategy {
}
}
impl TryFrom<u8> for FilterStrategy {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0..=4 => Ok(Self::Basic(value.try_into()?)),
5 => Ok(Self::MinSum),
6 => Ok(Self::Entropy),
7 => Ok(Self::Bigrams),
8 => Ok(Self::BigEnt),
9 => Ok(Self::Brute),
_ => Err(()),
}
}
}
/// PNG delta filters
#[repr(u8)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]

View file

@ -26,7 +26,7 @@ use clap::ArgMatches;
mod cli;
use indexmap::IndexSet;
use log::{Level, LevelFilter, error, warn};
use oxipng::{Deflaters, InFile, Options, OutFile, PngError, StripChunks};
use oxipng::{Deflaters, FilterStrategy, InFile, Options, OutFile, PngError, StripChunks};
use rayon::prelude::*;
use crate::cli::DISPLAY_CHUNKS;
@ -198,10 +198,18 @@ fn parse_opts_into_struct(
};
if let Some(x) = matches.get_one::<IndexSet<u8>>("filters") {
opts.filter.clear();
for &f in x {
opts.filter.insert(f.try_into().unwrap());
}
opts.filter = x
.iter()
.map(|&f| match f {
0..=4 => FilterStrategy::Basic(f.try_into().unwrap()),
5 => FilterStrategy::MinSum,
6 => FilterStrategy::Entropy,
7 => FilterStrategy::Bigrams,
8 => FilterStrategy::BigEnt,
9 => FilterStrategy::Brute,
_ => unreachable!(),
})
.collect();
}
if let Some(&num) = matches.get_one::<u64>("timeout") {