Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed clippy warnings #22

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- run: cargo build
- run: cargo test --features serde
- run: cargo fmt --all -- --check
- run: cargo clippy
- run: cargo clippy -- -Dwarnings
2 changes: 1 addition & 1 deletion src/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ mod tests {
#[test]
fn user_defined_encoding() {
let actual = UserDefinedEncoding::new(DefaultEncoding::STAGES);
let expected = DefaultEncoding::default();
let expected = DefaultEncoding;
for v in 0..u8::MAX {
assert_eq!(actual.stage_by_prefix(v), expected.stage_by_prefix(v));
}
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<E: Encoding, const N: usize> OrdPath<E, N> {
pub fn try_from_str(s: &str, enc: E) -> Result<Self, Error> {
let mut v = Vec::new();
for x in s.split_terminator('.') {
v.push(i64::from_str_radix(x, 10)?);
v.push(x.parse::<i64>()?);
}

Self::try_from_ordinals(&v, enc)
Expand Down Expand Up @@ -255,20 +255,20 @@ impl<E: Encoding, const N: usize> OrdPath<E, N> {

if bits > 0 || bytes > 0 {
bytes += bits.div_ceil(8) as usize;
bits = bits & 7;
bits &= 7;
}
}
}

let mut path = Self::new(bytes, self.encoding().clone()).unwrap();
let dst = path.raw.as_mut_slice();
if dst.len() > 0 {
if !dst.is_empty() {
dst.copy_from_slice(&src[..dst.len()]);

let bits = (8 - bits) & 7;
let last = &mut dst[dst.len() - 1];

*last = *last & (u8::MAX << bits);
*last &= u8::MAX << bits;
path.raw.set_trailing_bits(bits);
}

Expand All @@ -295,7 +295,7 @@ impl<E: Encoding + PartialEq, const N: usize> PartialOrd for OrdPath<E, N> {
impl<E: Encoding, const N: usize> Hash for OrdPath<E, N> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
state.write(&self);
state.write(self);
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ impl<E: Encoding, const N: usize> Display for OrdPath<E, N> {
let mut ordinals = self.ordinals();
if let Some(value) = ordinals.next() {
write!(f, "{}", value)?;
while let Some(value) = ordinals.next() {
for value in ordinals {
write!(f, ".{}", value)?;
}
}
Expand Down Expand Up @@ -483,10 +483,10 @@ mod tests {
assert(&[4295037272, 4295037272, 4440, 344]);
assert(&[4295037272, 4295037272, 4440, 4440]);

assert(&[0 + 3]);
assert(&[0 + 3, 8 + 5]);
assert(&[3]);
assert(&[3, 8 + 5]);
assert(&[4440 + 13, 4440 + 179, 4440 + 7541, 8 + 11]);
assert(&[4440 + 13, 4440 + 179, 4440 + 7541, 8 + 11, 0 + 3]);
assert(&[4440 + 13, 4440 + 179, 4440 + 7541, 8 + 11, 3]);
assert(&[4440 + 13, 4440 + 179, 4440 + 7541, 4440 + 123]);
assert(&[4440 + 13, 4440 + 179, 4440 + 7541, 4440 + 123, 88 + 11]);
assert(&[4295037272 + 31, 4295037272 + 6793]);
Expand Down Expand Up @@ -533,8 +533,8 @@ mod tests {
fn path_clone() {
fn assert(o: &[i64]) {
assert_eq!(
<OrdPath>::from_ordinals(&o, DefaultEncoding).clone(),
<OrdPath>::from_ordinals(&o, DefaultEncoding)
<OrdPath>::from_ordinals(o, DefaultEncoding).clone(),
<OrdPath>::from_ordinals(o, DefaultEncoding)
);
}

Expand Down Expand Up @@ -567,8 +567,8 @@ mod tests {
#[test]
fn path_is_ancestor() {
fn assert(e: bool, a: &[i64], d: &[i64]) {
let x = <OrdPath>::from_ordinals(&a, DefaultEncoding);
let y = <OrdPath>::from_ordinals(&d, DefaultEncoding);
let x = <OrdPath>::from_ordinals(a, DefaultEncoding);
let y = <OrdPath>::from_ordinals(d, DefaultEncoding);

assert_eq!(e, x.is_ancestor_of(&y));
assert_eq!(e, y.is_descendant_of(&x));
Expand Down
7 changes: 3 additions & 4 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ impl<const N: usize> RawOrdPath<N> {
let len = Metadata::bytes_for(data);

let data = size_of::<RawOrdPath<N>>() - len;
let len = Metadata::bytes_for(data);

len
Metadata::bytes_for(data)
};

const INLINE_META_MASK: usize =
Expand Down Expand Up @@ -181,7 +180,7 @@ impl<const N: usize> RawOrdPath<N> {
let self_slice = self.as_slice();
let other_slice = other.as_slice();

if self_slice.len() > 0 && self_slice.len() <= other_slice.len() {
if !self_slice.is_empty() && self_slice.len() <= other_slice.len() {
let len = self_slice.len() - 1;

if self_slice[..len].eq(&other_slice[..len]) {
Expand All @@ -200,7 +199,7 @@ impl<const N: usize> RawOrdPath<N> {
}
}

self_slice.len() == 0 && other_slice.len() != 0
self_slice.is_empty() && !other_slice.is_empty()
}
}

Expand Down
Loading