bytes: Fixed `0.1b` rounding up instead of down.

Fortune for units's current commit: Curse − 凶
master
Avril 2 weeks ago
parent 5cde9e6885
commit 3e33be5c32
Signed by: flanchan
GPG Key ID: 284488987C31F630

4
Cargo.lock generated

@ -4,9 +4,9 @@ version = 4
[[package]]
name = "lazy_static"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "rustc_version"

@ -48,7 +48,7 @@ impl Conversion for Bytes
}
let (o, u) = match input.char_indices().last().map(|(idx, chr)| (chr.to_lowercase().next().unwrap(), &input[..idx])) {
Some((chr, _)) if chr.is_numeric() => return Ok((parse!(input: Self::Output), Some(1))),
Some((chr, _)) if chr.is_numeric() => return Ok((parse!(input: Self::Output), Some(1))),
Some((ref chr, non)) if SUFFIX.contains_key(chr) => (parse!(non: IntermediateUnit), *SUFFIX.get(chr).unwrap()),
@ -59,6 +59,11 @@ impl Conversion for Bytes
if o.is_sign_negative() {
return Err(ConversionError::new_for(self, "Negative byte offsets not supported"));
}
// NOTE: Special-case truncation for if `1.xb` is used.
if u == 1 {
return Ok((o.trunc() as Self::Output, Some(1)));
}
Ok((multiply(o, u), Some(u)))
}

Loading…
Cancel
Save