Remove TryFrom for FilterStrategy
This commit is contained in:
parent
654552cf73
commit
8d53e52408
2 changed files with 13 additions and 21 deletions
|
|
@ -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
|
/// PNG delta filters
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -26,7 +26,7 @@ use clap::ArgMatches;
|
||||||
mod cli;
|
mod cli;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use log::{Level, LevelFilter, error, warn};
|
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 rayon::prelude::*;
|
||||||
|
|
||||||
use crate::cli::DISPLAY_CHUNKS;
|
use crate::cli::DISPLAY_CHUNKS;
|
||||||
|
|
@ -198,10 +198,18 @@ fn parse_opts_into_struct(
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(x) = matches.get_one::<IndexSet<u8>>("filters") {
|
if let Some(x) = matches.get_one::<IndexSet<u8>>("filters") {
|
||||||
opts.filter.clear();
|
opts.filter = x
|
||||||
for &f in x {
|
.iter()
|
||||||
opts.filter.insert(f.try_into().unwrap());
|
.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") {
|
if let Some(&num) = matches.get_one::<u64>("timeout") {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue