diff --git a/Cargo.lock b/Cargo.lock index 5d1c579..10fd688 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/src/conv/bytes.rs b/src/conv/bytes.rs index 808d2ec..e5e4ba0 100644 --- a/src/conv/bytes.rs +++ b/src/conv/bytes.rs @@ -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))) }