enable as_conversions lint

There were some very, uh, creative (and inconsistent) ways to convert
between numeric types in here...
This commit is contained in:
Charles Hall 2024-05-12 15:32:23 -07:00
parent a78bf8f50b
commit 71c48f66c4
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
21 changed files with 195 additions and 91 deletions

View file

@ -154,10 +154,8 @@ impl Service {
} else {
let (exact_width, exact_height) = {
// Copied from image::dynimage::resize_dimensions
let ratio = u64::from(original_width) * u64::from(height);
let nratio = u64::from(width) * u64::from(original_height);
let use_width = nratio <= ratio;
let use_width = (u64::from(width) * u64::from(original_height))
<= (u64::from(original_width) * u64::from(height));
let intermediate = if use_width {
u64::from(original_height) * u64::from(width)
/ u64::from(original_width)
@ -167,21 +165,23 @@ impl Service {
};
if use_width {
if intermediate <= u64::from(::std::u32::MAX) {
(width, intermediate as u32)
(width, intermediate.try_into().unwrap_or(u32::MAX))
} else {
(
(u64::from(width) * u64::from(::std::u32::MAX) / intermediate)
as u32,
.try_into()
.unwrap_or(u32::MAX),
::std::u32::MAX,
)
}
} else if intermediate <= u64::from(::std::u32::MAX) {
(intermediate as u32, height)
(intermediate.try_into().unwrap_or(u32::MAX), height)
} else {
(
::std::u32::MAX,
(u64::from(height) * u64::from(::std::u32::MAX) / intermediate)
as u32,
.try_into()
.unwrap_or(u32::MAX),
)
}
};