Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj committed Aug 4, 2024
1 parent 1031c95 commit de956d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
16 changes: 5 additions & 11 deletions serde_json_path_core/src/spec/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
/// The value must be within the range [-(2<sup>53</sup>)+1, (2<sup>53</sup>)-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
Expand All @@ -24,15 +24,15 @@ const MIN: i64 = -9_007_199_254_740_992 + 1;

impl Integer {
fn try_new(value: i64) -> Result<Self, IntegerError> {
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`
Expand Down Expand Up @@ -72,12 +72,6 @@ impl Integer {
}
}

impl Default for Integer {
fn default() -> Self {
Self(0)
}
}

impl TryFrom<i64> for Integer {
type Error = IntegerError;

Expand Down
5 changes: 1 addition & 4 deletions serde_json_path_core/src/spec/selector/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ fn normalize_slice_index(index: Integer, len: Integer) -> Option<Integer> {
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))
}
}

0 comments on commit de956d1

Please sign in to comment.