diff --git a/Cargo.toml b/Cargo.toml index 1e646e5..48398ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] authors = ["Heinz N. Gies "] description = "Multi backend HashMap for higher performance on different key space sizes" -edition = "2018" +edition = "2024" license = "Apache-2.0/MIT" name = "halfbrown" repository = "https://github.com/Licenser/halfbrown" -version = "0.3.0" +version = "0.4.0" [dependencies] hashbrown = "0.16" diff --git a/src/lib.rs b/src/lib.rs index 920f9e6..57294a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ //! Note: Most of the documentation is taken from //! rusts hashmap.rs and should be considered under //! their copyright. - #![warn(unused_extern_crates)] #![deny( clippy::all, @@ -26,7 +25,7 @@ clippy::pedantic )] // We might want to revisit inline_always -#![allow(clippy::module_name_repetitions, clippy::inline_always)] +#![allow(clippy::module_name_repetitions)] #![deny(missing_docs)] mod entry; @@ -436,7 +435,7 @@ impl SizedHashMap Drain { + pub fn drain(&'_ mut self) -> Drain<'_, K, V, VEC_LIMIT_UPPER> { match &mut self.0 { HashMapInt::Map(m) => Drain(DrainInt::Map(m.drain())), HashMapInt::Vec(m) => Drain(DrainInt::Vec(m.drain())), @@ -562,14 +561,14 @@ where /// assert_eq!(letters[&'u'], 1); /// assert_eq!(letters.get(&'y'), None); /// ``` - pub fn entry(&mut self, key: K) -> Entry + pub fn entry(&'_ mut self, key: K) -> Entry<'_, K, V, VEC_LIMIT_UPPER, S> where S: Default, { - if let HashMapInt::Vec(m) = &self.0 { - if m.len() >= VEC_LIMIT_UPPER { - self.swap_backend_to_map(); - } + if let HashMapInt::Vec(m) = &self.0 + && m.len() >= VEC_LIMIT_UPPER + { + self.swap_backend_to_map(); } match &mut self.0 { HashMapInt::Map(m) => m.entry(key).into(), @@ -838,12 +837,12 @@ where { match &mut self.0 { HashMapInt::Map(m) => { - m.insert_unique_unchecked(k, v); + unsafe { m.insert_unique_unchecked(k, v) }; } HashMapInt::Vec(m) => { if m.len() >= VEC_LIMIT_UPPER { let map = self.swap_backend_to_map(); - map.insert_unique_unchecked(k, v); + unsafe { map.insert_unique_unchecked(k, v) }; } else { m.insert_nocheck(k, v); } @@ -930,10 +929,10 @@ where where S: Default, { - if let HashMapInt::Vec(m) = &self.0 { - if m.len() >= VEC_LIMIT_UPPER { - self.swap_backend_to_map(); - } + if let HashMapInt::Vec(m) = &self.0 + && m.len() >= VEC_LIMIT_UPPER + { + self.swap_backend_to_map(); } match &mut self.0 { HashMapInt::Vec(m) => RawEntryBuilderMut::from(m.raw_entry_mut()), @@ -978,7 +977,7 @@ where } self.iter() - .all(|(key, value)| other.get(key).map_or(false, |v| *value == *v)) + .all(|(key, value)| other.get(key).is_some_and(|v| *value == *v)) } } diff --git a/src/serde.rs b/src/serde.rs index 368df68..8d8b6ef 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -13,7 +13,7 @@ mod se { S: Serializer, { let mut map = serializer.serialize_map(Some(self.len()))?; - for (k, v) in self.iter() { + for (k, v) in self { map.serialize_entry(k, v)?; } map.end() diff --git a/src/vecmap.rs b/src/vecmap.rs index d8a2402..48880fc 100644 --- a/src/vecmap.rs +++ b/src/vecmap.rs @@ -5,8 +5,8 @@ mod raw_entry; pub(crate) use self::entry::*; pub(crate) use self::raw_entry::*; -use crate::vectypes::VecDrain; use crate::DefaultHashBuilder; +use crate::vectypes::VecDrain; use std::borrow::Borrow; #[derive(Debug, Clone)] @@ -43,7 +43,7 @@ where } self.iter() - .all(|(key, value)| other.get(key).map_or(false, |v| value == v.borrow())) + .all(|(key, value)| other.get(key).is_some_and(|v| value == v.borrow())) } } @@ -83,7 +83,7 @@ impl VecMap { #[cfg(feature = "arraybackend")] #[inline] - pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self { + pub fn with_capacity_and_hasher(_capacity: usize, hash_builder: S) -> Self { let v = arrayvec::ArrayVec::new(); Self { v, hash_builder } } @@ -132,7 +132,7 @@ impl VecMap { } #[inline] - pub(crate) fn drain(&mut self) -> VecDrain<(K, V), N> { + pub(crate) fn drain(&'_ mut self) -> VecDrain<'_, (K, V), N> { self.v.drain(..) } @@ -214,7 +214,7 @@ impl VecMap { self.v.push((k, v)); } - pub(crate) fn entry(&mut self, key: K) -> Entry + pub(crate) fn entry(&'_ mut self, key: K) -> Entry<'_, K, V, N, S> where K: Eq, { @@ -339,7 +339,7 @@ impl VecMap { /// inserts a non existing element and returns it's position #[inline] unsafe fn get_mut_idx(&mut self, idx: usize) -> (&mut K, &mut V) { - let r = self.v.get_unchecked_mut(idx); + let r = unsafe { self.v.get_unchecked_mut(idx) }; (&mut r.0, &mut r.1) } #[cfg(feature = "arraybackend")] diff --git a/src/vecmap/raw_entry.rs b/src/vecmap/raw_entry.rs index c24e729..53bbed3 100644 --- a/src/vecmap/raw_entry.rs +++ b/src/vecmap/raw_entry.rs @@ -114,7 +114,7 @@ impl<'a, K, V, const N: usize, S> RawEntryBuilderMut<'a, K, V, N, S> { where for<'b> F: FnMut(&'b K) -> bool, { - for (idx, (ref key, _v)) in self.map.v.iter().enumerate() { + for (idx, (key, _v)) in self.map.v.iter().enumerate() { if is_match(key) { return RawEntryMut::Occupied(RawOccupiedEntryMut { idx, map: self.map }); } @@ -332,7 +332,7 @@ impl<'a, K, V, const N: usize, S> RawOccupiedEntryMut<'a, K, V, N, S> { #[inline] pub fn get_key_value(&mut self) -> (&K, &V) { unsafe { - let (ref key, ref value) = &self.map.v.get_unchecked(self.idx); + let (key, value) = &self.map.v.get_unchecked(self.idx); (key, value) } }