num_decimal_digits doesn't know the difference between no line numbers in the group and there being a 0 line number, causing unnecessary indentation
|
// instead of taking the String length or dividing by 10 while > 0, we multiply a limit by 10 until |
|
// we're higher. If the loop isn't exited by the `return`, the last multiplication will wrap, which |
|
// is OK, because while we cannot fit a higher power of 10 in a usize, the loop will end anyway. |
|
// This is also why we need the max number of decimal digits within a `usize`. |
|
fn num_decimal_digits(num: usize) -> usize { |
|
#[cfg(target_pointer_width = "64")] |
|
const MAX_DIGITS: usize = 20; |
|
|
|
#[cfg(target_pointer_width = "32")] |
|
const MAX_DIGITS: usize = 10; |
|
|
|
#[cfg(target_pointer_width = "16")] |
|
const MAX_DIGITS: usize = 5; |
|
|
|
let mut lim = 10; |
|
for num_digits in 1..MAX_DIGITS { |
|
if num < lim { |
|
return num_digits; |
|
} |
|
lim = lim.wrapping_mul(10); |
|
} |
|
MAX_DIGITS |
|
} |
num_decimal_digitsdoesn't know the difference between no line numbers in the group and there being a0line number, causing unnecessary indentationannotate-snippets-rs/src/renderer/render.rs
Lines 2270 to 2292 in 411dd35