Add some config for jxl encode

Remove clap_num dep
This commit is contained in:
2025-09-14 11:08:46 +08:00
parent 199442ac6d
commit 5fb7a8b601
11 changed files with 183 additions and 37 deletions

27
src/utils/num_range.rs Normal file
View File

@@ -0,0 +1,27 @@
//! Functions for parsing numbers within a range.
/// Check if a value is within the specified range.
pub fn check_range<T>(val: T, min: T, max: T) -> Result<T, String>
where
T: PartialOrd,
T: std::fmt::Display,
{
if val < min {
return Err(format!("Value {} is less than minimum {}", val, min));
} else if val > max {
return Err(format!("Value {} is greater than maximum {}", val, max));
}
Ok(val)
}
/// Parse a number from a string and check if it is within the specified range.
pub fn number_range<T>(s: &str, min: T, max: T) -> Result<T, String>
where
T: std::str::FromStr,
<T as std::str::FromStr>::Err: std::fmt::Display,
T: PartialOrd,
T: std::fmt::Display,
{
debug_assert!(min <= max, "min should be less than or equal to max");
let val = s.parse::<T>().map_err(|e| format!("{}", e))?;
check_range(val, min, max)
}