From de956d1402d66edc7de4d6aec515faa07f60f9ee Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Sun, 4 Aug 2024 08:45:14 -0700 Subject: [PATCH] chore: clippy --- serde_json_path_core/src/spec/integer.rs | 16 +++++----------- serde_json_path_core/src/spec/selector/slice.rs | 5 +---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/serde_json_path_core/src/spec/integer.rs b/serde_json_path_core/src/spec/integer.rs index 1e5eda2..6c86863 100644 --- a/serde_json_path_core/src/spec/integer.rs +++ b/serde_json_path_core/src/spec/integer.rs @@ -14,7 +14,7 @@ use std::{ /// The value must be within the range [-(253)+1, (253)-1]). /// /// [ijson]: https://www.rfc-editor.org/rfc/rfc7493#section-2.2 -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct Integer(i64); /// The maximum allowed value, 2^53 - 1 @@ -24,15 +24,15 @@ const MIN: i64 = -9_007_199_254_740_992 + 1; impl Integer { fn try_new(value: i64) -> Result { - if value < MIN || value > MAX { - return Err(IntegerError::OutOfBounds); + if !(MIN..=MAX).contains(&value) { + Err(IntegerError::OutOfBounds) } else { - return Ok(Self(value)); + Ok(Self(value)) } } fn check(&self) -> bool { - self.0 >= MIN && self.0 <= MAX + (MIN..=MAX).contains(&self.0) } /// Get an [`Integer`] from an `i64` @@ -72,12 +72,6 @@ impl Integer { } } -impl Default for Integer { - fn default() -> Self { - Self(0) - } -} - impl TryFrom for Integer { type Error = IntegerError; diff --git a/serde_json_path_core/src/spec/selector/slice.rs b/serde_json_path_core/src/spec/selector/slice.rs index 8d260f1..6d359fc 100644 --- a/serde_json_path_core/src/spec/selector/slice.rs +++ b/serde_json_path_core/src/spec/selector/slice.rs @@ -220,9 +220,6 @@ fn normalize_slice_index(index: Integer, len: Integer) -> Option { if index >= 0 { Some(index) } else { - index - .checked_abs() - .and_then(|i| len.checked_sub(i)) - .and_then(|i| Integer::try_from(i).ok()) + index.checked_abs().and_then(|i| len.checked_sub(i)) } }