diff --git a/src/filters.rs b/src/filters.rs index 10d0af6f..26e93b68 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -41,22 +41,6 @@ impl Display for FilterStrategy { } } -impl TryFrom for FilterStrategy { - type Error = (); - - fn try_from(value: u8) -> Result { - 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)] diff --git a/src/main.rs b/src/main.rs index c8732914..17909628 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>("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::("timeout") {