Skip to content

Commit

Permalink
Address some lints, silence others
Browse files Browse the repository at this point in the history
  • Loading branch information
mqudsi committed May 9, 2024
1 parent fd866ed commit 2d59550
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ impl<T: sealed::FormatterSize> SizeFormatter<T> {
y => {
write!(fmt, "-")?;

// The absolute magnitude of T::min_value() for a signed number is one more than
// that of T::max_value(), meaning T::min_value().abs() will panic.
// The absolute magnitude of T::MIN for a signed number is one more than
// that of T::MAX, meaning T::MIN.abs() will panic.
match y.checked_abs() {
Some(abs) => abs as u64,
None => i64::max_value() as u64,
None => i64::MAX as u64,
}
}
};
Expand Down Expand Up @@ -443,7 +443,7 @@ const BASE10_RULES: [FormatRule; 17] = [
unit: Unit::Petabyte,
},
FormatRule {
less_than: u64::max_value(),
less_than: u64::MAX,
formatter: |fmt, bytes| write!(fmt, "{:0}", bytes as f64 / (EXABYTE as f64)),
unit: Unit::Exabyte,
},
Expand Down Expand Up @@ -531,7 +531,7 @@ const BASE2_RULES: [FormatRule; 17] = [
unit: Unit::Pebibyte,
},
FormatRule {
less_than: u64::max_value(),
less_than: u64::MAX,
formatter: |fmt, bytes| write!(fmt, "{:0}", bytes as f64 / (EXBIBYTE as f64)),
unit: Unit::Exbibyte,
},
Expand Down
1 change: 1 addition & 0 deletions src/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl Size {
/// let size = Size::from_str("12.34 KB").unwrap();
/// assert_eq!(size.bytes(), 12_340);
/// ```
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Result<Size, crate::ParseSizeError> {
FromStr::from_str(s)
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), allow(clippy::unnecessary_cast))]
#![warn(missing_docs)]

//! This crate provides an ergonomic, type-safe, and aesthetically-pleasing [`Size`] type that can
Expand Down
6 changes: 3 additions & 3 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'de> de::Visitor<'de> for SizeVisitor {
where
E: de::Error,
{
if value > std::i64::MAX as u64 {
if value > i64::MAX as u64 {
Err(E::custom(format!("u64 size {} is out of range", value)))
} else {
Ok(Size {
Expand All @@ -36,7 +36,7 @@ impl<'de> de::Visitor<'de> for SizeVisitor {
where
E: de::Error,
{
if value.is_infinite() || value > std::i64::MAX as f32 || value < std::i64::MIN as f32 {
if value.is_infinite() || value > i64::MAX as f32 || value < i64::MIN as f32 {
Err(E::custom(format!("f32 size {} is out of range", value)))
} else {
Ok(Size {
Expand All @@ -49,7 +49,7 @@ impl<'de> de::Visitor<'de> for SizeVisitor {
where
E: de::Error,
{
if value.is_infinite() || value > std::i64::MAX as f64 || value < std::i64::MIN as f64 {
if value.is_infinite() || value > i64::MAX as f64 || value < i64::MIN as f64 {
Err(E::custom(format!("f64 size {} is out of range", value)))
} else {
Ok(Size {
Expand Down
12 changes: 6 additions & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ fn negative_tests() {

#[test]
fn integral_limits() {
assert_eq!("8 EiB", format!("{}", Size::from_bytes(i64::max_value())));
assert_eq!("-8 EiB", format!("{}", Size::from_bytes(i64::min_value())));
assert_eq!("8 EiB", format!("{}", Size::from_bytes(i64::MAX)));
assert_eq!("-8 EiB", format!("{}", Size::from_bytes(i64::MIN)));

assert_eq!("8 EiB", format!("{}", Size::from_kib(u64::max_value())));
assert_eq!("0 bytes", format!("{}", Size::from_kib(u64::min_value())));
assert_eq!("8 EiB", format!("{}", Size::from_kib(u64::MAX)));
assert_eq!("0 bytes", format!("{}", Size::from_kib(u64::MIN)));

// Also test for the old-style API, which does no math at the point of creation
assert_eq!("8 EiB", format!("{}", Size::Bytes(u64::max_value())));
assert_eq!("0 bytes", format!("{}", Size::Bytes(u64::min_value())));
assert_eq!("8 EiB", format!("{}", Size::Bytes(u64::MAX)));
assert_eq!("0 bytes", format!("{}", Size::Bytes(u64::MIN)));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/tests_nostd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn nostd_bytes() {
#[test]
fn nostd_integral_limits() {
// Test the old-style API, which does no math at the point of creation
assert_eq!(Size::from_bytes(i64::max_value()), Size::Bytes(u64::max_value()));
assert_eq!(Size::from_bytes(0), Size::Bytes(u64::min_value()));
assert_eq!(Size::from_bytes(i64::MAX), Size::Bytes(u64::MAX));
assert_eq!(Size::from_bytes(0), Size::Bytes(u64::MIN));
assert_eq!(Size::from_bytes(i64::MAX), Size::Bytes(u64::MAX - 1));
}

Expand Down

0 comments on commit 2d59550

Please sign in to comment.