diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9ccbc39 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +edition = "2021" +merge_derives = false +imports_granularity = "Crate" +normalize_comments = true +wrap_comments = true \ No newline at end of file diff --git a/src/collections/blazemap.rs b/src/collections/blazemap.rs index 099d634..c20765f 100644 --- a/src/collections/blazemap.rs +++ b/src/collections/blazemap.rs @@ -1,6 +1,8 @@ -use std::borrow::Borrow; -use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; +use std::{ + borrow::Borrow, + fmt::{Debug, Formatter}, + marker::PhantomData, +}; #[cfg(feature = "serde")] use { @@ -12,14 +14,16 @@ use { }, }; -use crate::collections::blazemap::entries::VacantEntryInner; pub use crate::collections::blazemap::{ entries::{Entry, OccupiedEntry, VacantEntry}, iters::{Drain, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut}, }; -use crate::traits::CapacityInfoProvider; -use crate::traits::KeyByOffsetProvider; -use crate::traits::{BlazeMapId, BlazeMapIdStatic, TypeInfoContainer}; +use crate::{ + collections::blazemap::entries::VacantEntryInner, + traits::{ + BlazeMapId, BlazeMapIdStatic, CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer, + }, +}; mod entries; mod iters; @@ -58,7 +62,8 @@ impl BlazeMap { self.len == 0 } - /// Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse. + /// Clears the map, removing all key-value pairs. Keeps the allocated memory + /// for reuse. #[inline] pub fn clear(&mut self) { self.inner.clear(); @@ -66,8 +71,9 @@ impl BlazeMap { } /// Shrinks the capacity of the map as much as possible. - /// It will drop down as much as possible while maintaining the internal rules - /// and possibly leaving some space in accordance with the resize policy. + /// It will drop down as much as possible while maintaining the internal + /// rules and possibly leaving some space in accordance with the resize + /// policy. #[inline] pub fn shrink_to_fit(&mut self) { if !self.is_empty() { @@ -91,7 +97,8 @@ impl BlazeMap { /// /// If the returned iterator is dropped before being fully consumed, /// it drops the remaining key-value pairs. - /// The returned iterator keeps a mutable borrow on the map to optimize its implementation. + /// The returned iterator keeps a mutable borrow on the map to optimize its + /// implementation. #[inline] pub fn drain(&mut self) -> Drain<'_, K, V> { debug_assert_eq!( @@ -109,7 +116,8 @@ impl BlazeMap where K: BlazeMapId, { - /// An iterator visiting all key-value pairs. The iterator element type is `(K, &V)`. + /// An iterator visiting all key-value pairs. The iterator element type is + /// `(K, &V)`. #[inline] #[must_use] pub fn iter(&self) -> Iter<'_, K, V> { @@ -125,8 +133,8 @@ where } } - /// An iterator visiting all key-value pairs, with mutable references to the values. - /// The iterator element type is `(K, &mut V)`. + /// An iterator visiting all key-value pairs, with mutable references to the + /// values. The iterator element type is `(K, &mut V)`. #[inline] pub fn iter_mut(&mut self) -> IterMut<'_, K, V> { debug_assert_eq!( @@ -163,7 +171,8 @@ where Values { inner: self.iter() } } - /// An iterator visiting all values mutably. The iterator element type is `&mut V`. + /// An iterator visiting all values mutably. The iterator element type is + /// `&mut V`. #[inline] pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> { debug_assert_eq!( @@ -239,8 +248,8 @@ where /// /// If the map did not have this key present, None is returned. /// - /// If the map did have this key present, the value is updated, and the old value is returned. - /// The key is not updated, though. + /// If the map did have this key present, the value is updated, and the old + /// value is returned. The key is not updated, though. #[inline] pub fn insert(&mut self, key: K, value: V) -> Option { debug_assert_eq!( @@ -277,7 +286,8 @@ where result } - /// Gets the given key’s corresponding entry in the map for in-place manipulation. + /// Gets the given key’s corresponding entry in the map for in-place + /// manipulation. #[inline] pub fn entry(&mut self, key: K) -> Entry<'_, K, V> { debug_assert_eq!( @@ -313,7 +323,8 @@ where } /// Creates a consuming iterator visiting all the keys. - /// The map cannot be used after calling this. The iterator element type is `K`. + /// The map cannot be used after calling this. The iterator element type is + /// `K`. #[inline] #[must_use] pub fn into_keys(self) -> IntoKeys { @@ -327,7 +338,8 @@ where } /// Creates a consuming iterator visiting all the values. - /// The map cannot be used after calling this. The iterator element type is `V`. + /// The map cannot be used after calling this. The iterator element type is + /// `V`. #[inline] #[must_use] pub fn into_values(self) -> IntoValues { diff --git a/src/collections/blazemap/entries.rs b/src/collections/blazemap/entries.rs index 98d4855..56c5570 100644 --- a/src/collections/blazemap/entries.rs +++ b/src/collections/blazemap/entries.rs @@ -4,7 +4,8 @@ use crate::prelude::BlazeMapId; /// A view into a single entry in a map, which may either be vacant or occupied. /// /// This enum is constructed -/// from the [`entry`] method on [`BlazeMap`](crate::collections::blazemap::BlazeMap). +/// from the [`entry`] method on +/// [`BlazeMap`](crate::collections::blazemap::BlazeMap). /// /// [`entry`]: crate::collections::blazemap::BlazeMap::entry pub enum Entry<'a, K, V> @@ -18,8 +19,9 @@ where } #[derive(Debug)] -/// A view into an occupied entry in a [`BlazeMap`](crate::collections::blazemap::BlazeMap). -/// It is part of the [`Entry`] enum. +/// A view into an occupied entry in a +/// [`BlazeMap`](crate::collections::blazemap::BlazeMap). It is part of the +/// [`Entry`] enum. pub struct OccupiedEntry<'a, K, V> where K: BlazeMapId, @@ -32,8 +34,9 @@ where } #[derive(Debug)] -/// A view into a vacant entry in a [`BlazeMap`](crate::collections::blazemap::BlazeMap). -/// It is part of the [`Entry`] enum. +/// A view into a vacant entry in a +/// [`BlazeMap`](crate::collections::blazemap::BlazeMap). It is part of the +/// [`Entry`] enum. pub struct VacantEntry<'a, K, V> where K: BlazeMapId, @@ -65,8 +68,9 @@ where } } - /// Ensures a value is in the entry by inserting the result of the default function if empty, - /// and returns a mutable reference to the value in the entry. + /// Ensures a value is in the entry by inserting the result of the default + /// function if empty, and returns a mutable reference to the value in + /// the entry. #[inline] pub fn or_insert_with(self, default: impl FnOnce() -> V) -> &'a mut V { match self { @@ -143,7 +147,8 @@ where /// Gets a mutable reference to the value in the entry. /// /// If you need a reference to the [`OccupiedEntry`] - /// which may outlive the destruction of the [`Entry`] value, see [`into_mut`]. + /// which may outlive the destruction of the [`Entry`] value, see + /// [`into_mut`]. /// /// [`into_mut`]: Self::into_mut #[inline] @@ -154,7 +159,8 @@ where /// Converts the [`OccupiedEntry`] into a mutable reference /// to the value in the entry with a lifetime bound to the map itself. /// - /// If you need multiple references to the [`OccupiedEntry`], see [`get_mut`]. + /// If you need multiple references to the [`OccupiedEntry`], see + /// [`get_mut`]. /// /// [`get_mut`]: Self::get_mut #[inline] @@ -181,7 +187,8 @@ impl<'a, K, V> VacantEntry<'a, K, V> where K: BlazeMapId, { - /// Gets the key that would be used when inserting a value through the [`VacantEntry`]. + /// Gets the key that would be used when inserting a value through the + /// [`VacantEntry`]. #[inline] pub fn key(&self) -> K { self.key diff --git a/src/collections/blazemap/iters.rs b/src/collections/blazemap/iters.rs index 22feef7..bb7b0dc 100644 --- a/src/collections/blazemap/iters.rs +++ b/src/collections/blazemap/iters.rs @@ -1,11 +1,15 @@ -use std::borrow::Borrow; -use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; -use std::panic::{RefUnwindSafe, UnwindSafe}; - -use crate::collections::blazemap::BlazeMap; -use crate::prelude::{BlazeMapId, BlazeMapIdStatic}; -use crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; +use std::{ + borrow::Borrow, + fmt::{Debug, Formatter}, + marker::PhantomData, + panic::{RefUnwindSafe, UnwindSafe}, +}; + +use crate::{ + collections::blazemap::BlazeMap, + prelude::{BlazeMapId, BlazeMapIdStatic}, + traits::{KeyByOffsetProvider, TypeInfoContainer}, +}; /// An iterator over the entries of a [`BlazeMap`]. /// @@ -61,8 +65,8 @@ pub struct Values<'a, K, V> { /// A mutable iterator over the values of a [`BlazeMap`]. /// -/// This `struct` is created by the [`values_mut`] method on [`BlazeMap`]. See its -/// documentation for more. +/// This `struct` is created by the [`values_mut`] method on [`BlazeMap`]. See +/// its documentation for more. /// /// [`values_mut`]: BlazeMap::values_mut pub struct ValuesMut<'a, K, V> { diff --git a/src/lib.rs b/src/lib.rs index 7ae5380..0601f2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,8 @@ //! Implements a [vector-based slab-like map](prelude::BlazeMap) //! with an interface similar to that of [`HashMap`](std::collections::HashMap), //! and also provides tools -//! for generating lightweight identifiers that can be type-safely used as keys for this map. +//! for generating lightweight identifiers that can be type-safely used as keys +//! for this map. /// Collection types. pub mod collections; @@ -34,5 +35,6 @@ pub mod external { #[cfg(loom)] pub use loom; - pub use {once_cell, parking_lot}; + pub use once_cell; + pub use parking_lot; } diff --git a/src/loom.rs b/src/loom.rs index c9720eb..9b688c2 100644 --- a/src/loom.rs +++ b/src/loom.rs @@ -1,5 +1,4 @@ -use std::cmp::Ordering; -use std::marker::PhantomData; +use std::{cmp::Ordering, marker::PhantomData}; use crate::prelude::AllInstancesIter; #[cfg(feature = "serde")] @@ -7,8 +6,9 @@ use serde::{Serialize, Serializer}; use crate::traits::{BlazeMapId, TypeInfoContainer}; -/// Provides `PartialOrd`, `Ord` and `Serialize` traits, which are derived as for original type, -/// for [`BlazeMapId`]s in the [`loom`](crate::external::loom) context. +/// Provides `PartialOrd`, `Ord` and `Serialize` traits, which are derived as +/// for original type, for [`BlazeMapId`]s in the +/// [`loom`](crate::external::loom) context. #[derive(Debug, Copy, Clone)] pub struct TestableId<'a, I, C> { id: I, diff --git a/src/traits.rs b/src/traits.rs index 35f4177..ec016c6 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,10 +1,13 @@ -use std::borrow::Borrow; -use std::fmt::{Debug, Formatter}; -use std::hash::{Hash, Hasher}; -use std::marker::PhantomData; -use std::ops::{Deref, Range}; - -/// Provides an interface for `blazemap` id types defined by type-generating macros. +use std::{ + borrow::Borrow, + fmt::{Debug, Formatter}, + hash::{Hash, Hasher}, + marker::PhantomData, + ops::{Deref, Range}, +}; + +/// Provides an interface for `blazemap` id types defined by type-generating +/// macros. pub trait BlazeMapId: Copy { /// Original key type. type OrigType: 'static + Clone + Eq + Hash; @@ -24,9 +27,11 @@ pub trait BlazeMapId: Copy { /// Provides an interface for `blazemap` key-wrapper id types /// defined by the [`define_key_wrapper`](crate::define_key_wrapper) -/// and [`define_key_wrapper_bounded`](crate::define_key_wrapper_bounded) macros. +/// and [`define_key_wrapper_bounded`](crate::define_key_wrapper_bounded) +/// macros. pub trait BlazeMapIdWrapper: BlazeMapId { - /// Creates a new instance of [`Self`] based on the [`Self::OrigType`](BlazeMapId::OrigType) instance. + /// Creates a new instance of [`Self`] based on the + /// [`Self::OrigType`](BlazeMapId::OrigType) instance. unsafe fn new(type_info_container: &Self::TypeInfoContainer, key: Self::OrigType) -> Self; } @@ -46,7 +51,8 @@ pub trait BlazeMapIdStatic: BlazeMapId { } /// Returns the static container - /// that holds all the necessary static information for the [`BlazeMapId`] type. + /// that holds all the necessary static information for the [`BlazeMapId`] + /// type. #[doc(hidden)] fn static_container() -> &'static Self::TypeInfoContainer; } @@ -54,7 +60,8 @@ pub trait BlazeMapIdStatic: BlazeMapId { /// Implements an interface for [`BlazeMapId`] key-wrapper static containers. #[doc(hidden)] pub trait WrapKey { - /// Creates an instance of [`BlazeMapId`] type that is unique to the given key. + /// Creates an instance of [`BlazeMapId`] type that is unique to the given + /// key. fn wrap_key(&self, key: I::OrigType) -> I; } @@ -62,8 +69,9 @@ pub trait TypeInfoContainer: 'static { /// Original key type. type OrigType; - /// Returns the provider of the current total number of registered unique `Self` identifiers. - /// Note that this provider isn't sequentially consistent. + /// Returns the provider of the current total number of registered unique + /// `Self` identifiers. Note that this provider isn't sequentially + /// consistent. #[doc(hidden)] fn capacity_info_provider(&self) -> impl Deref; @@ -75,15 +83,17 @@ pub trait TypeInfoContainer: 'static { ) -> impl Deref>; } -/// Provides the current total number of registered unique [`BlazeMapId`] identifiers. -/// Note that there is no guarantee of sequential consistency. +/// Provides the current total number of registered unique [`BlazeMapId`] +/// identifiers. Note that there is no guarantee of sequential consistency. #[doc(hidden)] pub trait CapacityInfoProvider { - /// Returns the current total number of registered unique [`BlazeMapId`] identifiers. + /// Returns the current total number of registered unique [`BlazeMapId`] + /// identifiers. fn offset_capacity(&self) -> usize; } -/// May unsafely return the registered key corresponding to the offset specified. +/// May unsafely return the registered key corresponding to the offset +/// specified. #[doc(hidden)] pub trait KeyByOffsetProvider { /// Returns the registered key corresponding to the offset specified. diff --git a/src/type_gen.rs b/src/type_gen.rs index ffaba9e..0cdff96 100644 --- a/src/type_gen.rs +++ b/src/type_gen.rs @@ -6,13 +6,15 @@ mod plain_id; #[cfg(all(test, not(loom)))] mod tests { - use crate::prelude::BlazeMapId; - use crate::{define_key_wrapper, define_key_wrapper_bounded, define_plain_id}; + use crate::{ + define_key_wrapper, define_key_wrapper_bounded, define_plain_id, prelude::BlazeMapId, + }; #[cfg(feature = "serde")] mod serde_compatible { - use crate::traits::BlazeMapId; - use crate::{define_key_wrapper, define_key_wrapper_bounded, define_plain_id}; + use crate::{ + define_key_wrapper, define_key_wrapper_bounded, define_plain_id, traits::BlazeMapId, + }; #[test] fn key_wrapper() { diff --git a/src/type_gen/key_wrapper.rs b/src/type_gen/key_wrapper.rs index f5cfa33..d776f82 100644 --- a/src/type_gen/key_wrapper.rs +++ b/src/type_gen/key_wrapper.rs @@ -1,30 +1,35 @@ -/// Creates a new type that acts as an `usize`-based replacement for the old type -/// that can be used as a key for `blazemap` collections. +/// Creates a new type that acts as an `usize`-based replacement for the old +/// type that can be used as a key for `blazemap` collections. /// -/// This macro supports optional inference of standard traits using the following syntax: +/// This macro supports optional inference of standard traits using the +/// following syntax: /// /// * `Derive(as for Original Type)` — derives traits as for the original type -/// for which `blazemap_key` is being registered. Each call to methods on these traits -/// requires an additional `.read` call on the internal synchronization primitive, -/// so — all other things being equal — their calls may be less optimal -/// than the corresponding calls on instances of the original key's type. -/// This method supports inference of the following traits: +/// for which `blazemap_key` is being registered. Each call to methods on +/// these traits requires an additional `.read` call on the internal +/// synchronization primitive, so — all other things being equal — their calls +/// may be less optimal than the corresponding calls on instances of the +/// original key's type. This method supports inference of the following +/// traits: /// * `Default` /// * `PartialOrd` (mutually exclusive with `Ord`) -/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with `PartialOrd`) +/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with +/// `PartialOrd`) /// * `Debug` /// * `Display` /// * `Serialize` (with `serde` feature only) /// * `Deserialize` (with `serde` feature only) -/// * `Derive(as for usize)` — derives traits in the same way as for -/// the serial number assigned when registering an instance of the original type -/// the first time [`BlazeMapIdWrapper::new`](crate::prelude::BlazeMapIdWrapper::new) was called. -/// Because methods inferred by this option do not require additional -/// locking on synchronization primitives, -/// they do not incur any additional overhead compared to methods inferred for plain `usize`. -/// This method supports inference of the following traits: +/// * `Derive(as for usize)` — derives traits in the same way as for the serial +/// number assigned when registering an instance of the original type the +/// first time +/// [`BlazeMapIdWrapper::new`](crate::prelude::BlazeMapIdWrapper::new) was +/// called. Because methods inferred by this option do not require additional +/// locking on synchronization primitives, they do not incur any additional +/// overhead compared to methods inferred for plain `usize`. This method +/// supports inference of the following traits: /// * `PartialOrd` (mutually exclusive with `Ord`) -/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with `PartialOrd`) +/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with +/// `PartialOrd`) /// /// # Example /// @@ -169,8 +174,7 @@ macro_rules! key_wrapper_derive { #[inline] fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> { use ::std::borrow::Borrow; - use $crate::traits::KeyByOffsetProvider; - use $crate::traits::TypeInfoContainer; + use $crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; let Self(lhs) = self; let Self(rhs) = other; let guard = ::static_container() @@ -197,8 +201,7 @@ macro_rules! key_wrapper_derive { #[inline] fn cmp(&self, other: &Self) -> ::std::cmp::Ordering { use ::std::borrow::Borrow; - use $crate::traits::KeyByOffsetProvider; - use $crate::traits::TypeInfoContainer; + use $crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; let Self(lhs) = self; let Self(rhs) = other; @@ -219,8 +222,7 @@ macro_rules! key_wrapper_derive { #[inline] fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { use ::std::borrow::Borrow; - use $crate::traits::KeyByOffsetProvider; - use $crate::traits::TypeInfoContainer; + use $crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; let mut f = f.debug_struct(::std::stringify!($new_type)); let offset = self.0.into_offset(); @@ -239,8 +241,7 @@ macro_rules! key_wrapper_derive { #[inline] fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { use ::std::borrow::Borrow; - use $crate::traits::KeyByOffsetProvider; - use $crate::traits::TypeInfoContainer; + use $crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; let guard = ::static_container() .key_by_offset_provider(); @@ -276,8 +277,7 @@ macro_rules! key_wrapper_derive { S: $crate::external::serde::Serializer, { use ::std::borrow::Borrow; - use $crate::traits::KeyByOffsetProvider; - use $crate::traits::TypeInfoContainer; + use $crate::traits::{KeyByOffsetProvider, TypeInfoContainer}; unsafe { ::static_container() diff --git a/src/type_gen/key_wrapper_bounded.rs b/src/type_gen/key_wrapper_bounded.rs index 05a8111..c92f542 100644 --- a/src/type_gen/key_wrapper_bounded.rs +++ b/src/type_gen/key_wrapper_bounded.rs @@ -1,30 +1,34 @@ -/// Creates a new type that acts as an `usize`-based replacement for the old type -/// that can be used as a key for `blazemap` collections. +/// Creates a new type that acts as an `usize`-based replacement for the old +/// type that can be used as a key for `blazemap` collections. /// Being an analogue of [`define_key_wrapper`](crate::define_key_wrapper) /// for the case when the user could statically guarantee -/// that the number of unique keys doesn't exceed `MAX_CAP`, it's optimized for read operations -/// so that they don't create any multi-thread contention. +/// that the number of unique keys doesn't exceed `MAX_CAP`, it's optimized for +/// read operations so that they don't create any multi-thread contention. /// -/// This macro supports optional inference of standard traits using the following syntax: +/// This macro supports optional inference of standard traits using the +/// following syntax: /// /// * `Derive(as for Original Type)` — derives traits as for the original type -/// for which `blazemap_key` is being registered. -/// This method supports inference of the following traits: +/// for which `blazemap_key` is being registered. This method supports +/// inference of the following traits: /// * `Default` /// * `PartialOrd` (mutually exclusive with `Ord`) -/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with `PartialOrd`) +/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with +/// `PartialOrd`) /// * `Debug` /// * `Display` /// * `Serialize` (with `serde` feature only) /// * `Deserialize` (with `serde` feature only) -/// * `Derive(as for usize)` — derives traits in the same way as for -/// the serial number assigned when registering an instance of the original type -/// the first time [`BlazeMapIdWrapper::new`](crate::prelude::BlazeMapIdWrapper::new) was called. -/// Methods inferred by this option do not incur any additional overhead -/// compared to methods inferred for plain `usize`. -/// This method supports inference of the following traits: +/// * `Derive(as for usize)` — derives traits in the same way as for the serial +/// number assigned when registering an instance of the original type the +/// first time +/// [`BlazeMapIdWrapper::new`](crate::prelude::BlazeMapIdWrapper::new) was +/// called. Methods inferred by this option do not incur any additional +/// overhead compared to methods inferred for plain `usize`. This method +/// supports inference of the following traits: /// * `PartialOrd` (mutually exclusive with `Ord`) -/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with `PartialOrd`) +/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with +/// `PartialOrd`) /// /// # Example /// diff --git a/src/type_gen/plain_id.rs b/src/type_gen/plain_id.rs index 77b7f35..b3faba2 100644 --- a/src/type_gen/plain_id.rs +++ b/src/type_gen/plain_id.rs @@ -1,16 +1,18 @@ /// Creates a new type based on incrementally generated `usize` instances /// that can be used as a key for `blazemap` collections. /// -/// This macro supports optional inference of standard traits using the following syntax: +/// This macro supports optional inference of standard traits using the +/// following syntax: /// -/// * `Derive` — derives traits in the same way as for -/// the serial number assigned when creating a new instance of the type. -/// Because methods inferred by this option do not require additional -/// locking on synchronization primitives, -/// they do not incur any additional overhead compared to methods inferred for plain `usize`. -/// This method supports inference of the following traits: +/// * `Derive` — derives traits in the same way as for the serial number +/// assigned when creating a new instance of the type. Because methods +/// inferred by this option do not require additional locking on +/// synchronization primitives, they do not incur any additional overhead +/// compared to methods inferred for plain `usize`. This method supports +/// inference of the following traits: /// * `PartialOrd` (mutually exclusive with `Ord`) -/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with `PartialOrd`) +/// * `Ord` (also derives `PartialOrd`, so mutually exclusive with +/// `PartialOrd`) /// * `Serialize` (with `serde` feature only) /// /// # Example diff --git a/src/type_info_containers/key_wrapper.rs b/src/type_info_containers/key_wrapper.rs index c87794e..5237068 100644 --- a/src/type_info_containers/key_wrapper.rs +++ b/src/type_info_containers/key_wrapper.rs @@ -1,15 +1,18 @@ -use std::borrow::Borrow; -use std::collections::hash_map::Entry; -use std::collections::HashMap; -use std::hash::Hash; -use std::ops::Deref; +use std::{ + borrow::Borrow, + collections::{hash_map::Entry, HashMap}, + hash::Hash, + ops::Deref, +}; #[cfg(not(loom))] use once_cell::sync::Lazy; -use crate::prelude::BlazeMapId; -use crate::sync::RwLock; -use crate::traits::{CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer, WrapKey}; +use crate::{ + prelude::BlazeMapId, + sync::RwLock, + traits::{CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer, WrapKey}, +}; /// Global, statically initialized container with correspondence mapping /// between blazemap offset wrappers and original keys. @@ -49,8 +52,9 @@ impl StaticContainer { /// /// # Safety /// Mustn't be used outside of loom tests, - /// since there is no guarantee that one [`BlazeMapId`](crate::prelude::BlazeMapId) - /// doesn't interact with different containers of the same type. + /// since there is no guarantee that one + /// [`BlazeMapId`](crate::prelude::BlazeMapId) doesn't interact with + /// different containers of the same type. #[inline] #[must_use] #[cfg(loom)] diff --git a/src/type_info_containers/key_wrapper_bounded.rs b/src/type_info_containers/key_wrapper_bounded.rs index fd31878..172ae99 100644 --- a/src/type_info_containers/key_wrapper_bounded.rs +++ b/src/type_info_containers/key_wrapper_bounded.rs @@ -1,9 +1,9 @@ -use std::collections::hash_map::Entry; -use std::collections::HashMap; -use std::hash::Hash; +use std::{ + collections::{hash_map::Entry, HashMap}, + hash::Hash, +}; -use std::borrow::Borrow; -use std::ops::Deref; +use std::{borrow::Borrow, ops::Deref}; #[cfg(not(loom))] use std::{ cell::UnsafeCell, @@ -12,8 +12,10 @@ use std::{ use crate::sync::{AtomicUsize, Ordering, RwLock}; -use crate::prelude::BlazeMapId; -use crate::traits::{CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer, WrapKey}; +use crate::{ + prelude::BlazeMapId, + traits::{CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer, WrapKey}, +}; #[cfg(loom)] use crate::sync::RwLockReadGuard; @@ -21,10 +23,11 @@ use crate::sync::RwLockReadGuard; /// Global, statically initialized container with correspondence mapping /// between blazemap index wrappers and original keys. /// -/// Being an analogue of [`KeyWrapperStaticContainer`](crate::type_info_containers::key_wrapper::StaticContainer) +/// Being an analogue of +/// [`KeyWrapperStaticContainer`](crate::type_info_containers::key_wrapper::StaticContainer) /// for the case when the user could statically guarantee -/// that the number of unique keys doesn't exceed `CAP`, it's optimized for read operations -/// so that they don't create any multi-thread contention. +/// that the number of unique keys doesn't exceed `CAP`, it's optimized for read +/// operations so that they don't create any multi-thread contention. #[cfg(not(loom))] #[doc(hidden)] #[derive(Debug)] @@ -74,8 +77,9 @@ impl StaticContainer { /// /// # Safety /// Mustn't be used outside of loom tests, - /// since there is no guarantee that one [`BlazeMapId`](crate::prelude::BlazeMapId) - /// doesn't interact with different containers of the same type. + /// since there is no guarantee that one + /// [`BlazeMapId`](crate::prelude::BlazeMapId) doesn't interact with + /// different containers of the same type. #[inline] #[must_use] #[cfg(loom)] diff --git a/src/type_info_containers/plain_id.rs b/src/type_info_containers/plain_id.rs index 4021e76..ada73bb 100644 --- a/src/type_info_containers/plain_id.rs +++ b/src/type_info_containers/plain_id.rs @@ -1,6 +1,5 @@ use crate::sync::{AtomicUsize, Ordering}; -use std::borrow::Borrow; -use std::ops::Deref; +use std::{borrow::Borrow, ops::Deref}; use crate::traits::{CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer}; @@ -26,8 +25,9 @@ impl StaticContainer { /// /// # Safety /// Mustn't be used outside of loom tests, - /// since there is no guarantee that one [`BlazeMapId`](crate::prelude::BlazeMapId) - /// doesn't interact with different containers of the same type. + /// since there is no guarantee that one + /// [`BlazeMapId`](crate::prelude::BlazeMapId) doesn't interact with + /// different containers of the same type. #[inline] #[must_use] #[cfg(loom)] diff --git a/src/utils/offset_provider.rs b/src/utils/offset_provider.rs index 3e6acd5..e59c789 100644 --- a/src/utils/offset_provider.rs +++ b/src/utils/offset_provider.rs @@ -1,16 +1,16 @@ -use std::hash::Hash; -use std::num::NonZeroUsize; +use std::{hash::Hash, num::NonZeroUsize}; /// Holds and provides the `usize` offset. /// -/// Necessary to protect the internal `usize`, which, in the absence of this wrapper, -/// would be public in the module calling +/// Necessary to protect the internal `usize`, which, in the absence of this +/// wrapper, would be public in the module calling /// the [`define_key_wrapper`](crate::define_key_wrapper). /// /// Publicity of the internal `usize` may lead to: /// * UB if the programmer of the downstream crate would accidentally mutate it. -/// * Incorrect auto-derives of standard traits such as `Default`, `Debug`, `Display`, -/// `PartialOrd`, `Ord`, `serde::Serialize` and `serde::Deserialize`. +/// * Incorrect auto-derives of standard traits such as `Default`, `Debug`, +/// `Display`, `PartialOrd`, `Ord`, `serde::Serialize` and +/// `serde::Deserialize`. #[derive(Clone, Copy, Eq, PartialEq, Hash)] #[repr(transparent)] #[doc(hidden)] @@ -48,8 +48,10 @@ impl OffsetProvider { #[cfg(test)] mod tests { - use std::fmt::{Debug, Display}; - use std::num::NonZeroUsize; + use std::{ + fmt::{Debug, Display}, + num::NonZeroUsize, + }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/tests/loom.rs b/tests/loom.rs index 40cda7a..d18ecbd 100644 --- a/tests/loom.rs +++ b/tests/loom.rs @@ -6,10 +6,12 @@ use std::string::ToString; use loom::thread; -use blazemap::loom::TestableId; -use blazemap::prelude::BlazeMapIdWrapper; -use blazemap::traits::{CapacityInfoProvider, TypeInfoContainer}; -use blazemap::{define_key_wrapper, define_key_wrapper_bounded, define_plain_id}; +use blazemap::{ + define_key_wrapper, define_key_wrapper_bounded, define_plain_id, + loom::TestableId, + prelude::BlazeMapIdWrapper, + traits::{CapacityInfoProvider, TypeInfoContainer}, +}; fn run_model(f: F) where diff --git a/tests/miri.rs b/tests/miri.rs index 7f69de9..574956d 100644 --- a/tests/miri.rs +++ b/tests/miri.rs @@ -4,11 +4,9 @@ use std::io::Write; -use rand::prelude::StdRng; -use rand::{random, Rng, SeedableRng}; +use rand::{prelude::StdRng, random, Rng, SeedableRng}; -use blazemap::prelude::BlazeMap; -use blazemap::{define_key_wrapper, define_key_wrapper_bounded}; +use blazemap::{define_key_wrapper, define_key_wrapper_bounded, prelude::BlazeMap}; use crate::random_action::{ActionPeekWeights, EventWeights}; diff --git a/tests/random_action.rs b/tests/random_action.rs index 624a8be..0837977 100644 --- a/tests/random_action.rs +++ b/tests/random_action.rs @@ -13,8 +13,10 @@ use std::fmt::{Debug, Formatter, Write}; use rand::Rng; -use blazemap::prelude::BlazeMap; -use blazemap::traits::{BlazeMapId, BlazeMapIdStatic}; +use blazemap::{ + prelude::BlazeMap, + traits::{BlazeMapId, BlazeMapIdStatic}, +}; #[derive(Debug)] pub enum Action {