From ccdd36599094a6a0c5553e842d208cbc9330dacd Mon Sep 17 00:00:00 2001 From: Gianmarco Garrisi Date: Fri, 9 Aug 2024 21:18:40 +0200 Subject: [PATCH] Cargo fmt --- src/core_iterators.rs | 18 ++++++------------ src/double_priority_queue/iterators.rs | 9 +++------ src/double_priority_queue/mod.rs | 11 ++--------- src/priority_queue/iterators.rs | 6 ++---- src/priority_queue/mod.rs | 7 ++----- src/store.rs | 19 ++++++++----------- tests/double_priority_queue.rs | 1 - 7 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/core_iterators.rs b/src/core_iterators.rs index 259ffb3..9a2f541 100644 --- a/src/core_iterators.rs +++ b/src/core_iterators.rs @@ -42,13 +42,11 @@ pub(crate) mod std { /// `(item, priority)` in the queue. /// /// It can be obtained calling the `drain` method. -pub struct Drain<'a, I: 'a, P: 'a> -{ +pub struct Drain<'a, I: 'a, P: 'a> { pub(crate) iter: ::indexmap::map::Drain<'a, I, P>, } -impl<'a, I: 'a, P: 'a> Iterator for Drain<'a, I, P> -{ +impl<'a, I: 'a, P: 'a> Iterator for Drain<'a, I, P> { type Item = (I, P); fn next(&mut self) -> Option<(I, P)> { self.iter.next() @@ -73,13 +71,11 @@ impl FusedIterator for Drain<'_, I, P> {} /// `(item, priority)` in the queue. /// /// It can be obtained calling the `iter` method. -pub struct Iter<'a, I: 'a, P: 'a> -{ +pub struct Iter<'a, I: 'a, P: 'a> { pub(crate) iter: ::indexmap::map::Iter<'a, I, P>, } -impl<'a, I: 'a, P: 'a> Iterator for Iter<'a, I, P> -{ +impl<'a, I: 'a, P: 'a> Iterator for Iter<'a, I, P> { type Item = (&'a I, &'a P); fn next(&mut self) -> Option<(&'a I, &'a P)> { self.iter.next() @@ -104,13 +100,11 @@ impl FusedIterator for Iter<'_, I, P> {} /// `(item, priority)` that consumes the queue. /// /// It can be obtained calling the `into_iter` method from the `IntoIterator` trait. -pub struct IntoIter -{ +pub struct IntoIter { pub(crate) iter: ::indexmap::map::IntoIter, } -impl Iterator for IntoIter -{ +impl Iterator for IntoIter { type Item = (I, P); fn next(&mut self) -> Option<(I, P)> { self.iter.next() diff --git a/src/double_priority_queue/iterators.rs b/src/double_priority_queue/iterators.rs index c14cd1f..7c29ba6 100644 --- a/src/double_priority_queue/iterators.rs +++ b/src/double_priority_queue/iterators.rs @@ -134,7 +134,8 @@ impl<'a, I, P, H> FusedIterator for IterMut<'_, I, P, H> where P: Ord, H: BuildHasher, -{} +{ +} impl<'a, I: 'a, P: 'a, H: 'a> Drop for IterMut<'a, I, P, H> where @@ -197,8 +198,4 @@ where } } -impl FusedIterator for IntoSortedIter -where - P: Ord, -{} - +impl FusedIterator for IntoSortedIter where P: Ord {} diff --git a/src/double_priority_queue/mod.rs b/src/double_priority_queue/mod.rs index 5cfd2d3..e83b3fd 100644 --- a/src/double_priority_queue/mod.rs +++ b/src/double_priority_queue/mod.rs @@ -88,15 +88,13 @@ use std::mem::replace; /// ``` #[derive(Clone)] #[cfg(feature = "std")] -pub struct DoublePriorityQueue -{ +pub struct DoublePriorityQueue { pub(crate) store: Store, } #[derive(Clone)] #[cfg(not(feature = "std"))] -pub struct DoublePriorityQueue -{ +pub struct DoublePriorityQueue { pub(crate) store: Store, } @@ -247,7 +245,6 @@ impl DoublePriorityQueue where P: Ord, { - /// Return an iterator in arbitrary order over the /// (item, priority) elements in the queue. /// @@ -262,7 +259,6 @@ where IterMut::new(self) } - /// Returns the couple (item, priority) with the greatest /// priority in the queue, or None if it is empty. /// @@ -364,7 +360,6 @@ where P: Ord, H: BuildHasher, { - /// Returns the couple (item, priority) with the greatest /// priority in the queue, or None if it is empty. /// @@ -388,14 +383,12 @@ where } } - impl DoublePriorityQueue where P: Ord, I: Hash + Eq, H: BuildHasher, { - /// Insert the item-priority pair into the queue. /// /// If an element equal to `item` was already into the queue, diff --git a/src/priority_queue/iterators.rs b/src/priority_queue/iterators.rs index b1b080c..30f5f08 100644 --- a/src/priority_queue/iterators.rs +++ b/src/priority_queue/iterators.rs @@ -116,14 +116,12 @@ where /// /// It can be obtained calling the `into_sorted_iter` method. #[cfg(feature = "std")] -pub struct IntoSortedIter -{ +pub struct IntoSortedIter { pub(crate) pq: PriorityQueue, } #[cfg(not(feature = "std"))] -pub struct IntoSortedIter -{ +pub struct IntoSortedIter { pub(crate) pq: PriorityQueue, } diff --git a/src/priority_queue/mod.rs b/src/priority_queue/mod.rs index 27366df..a9f351d 100644 --- a/src/priority_queue/mod.rs +++ b/src/priority_queue/mod.rs @@ -79,15 +79,13 @@ use std::mem::replace; /// ``` #[derive(Clone, Debug)] #[cfg(feature = "std")] -pub struct PriorityQueue -{ +pub struct PriorityQueue { pub(crate) store: Store, } #[derive(Clone, Debug)] #[cfg(not(feature = "std"))] -pub struct PriorityQueue -{ +pub struct PriorityQueue { pub(crate) store: Store, } @@ -168,7 +166,6 @@ where } } - impl PriorityQueue { /// Returns an iterator in arbitrary order over the /// (item, priority) elements in the queue diff --git a/src/store.rs b/src/store.rs index 524cc42..7391f72 100644 --- a/src/store.rs +++ b/src/store.rs @@ -52,8 +52,7 @@ pub(crate) struct Position(pub usize); /// Internal storage of PriorityQueue and DoublePriorityQueue #[derive(Clone)] #[cfg(feature = "std")] -pub(crate) struct Store -{ +pub(crate) struct Store { pub map: IndexMap, // Stores the items and assign them an index pub heap: Vec, // Implements the heap of indexes pub qp: Vec, // Performs the translation from the index @@ -63,8 +62,7 @@ pub(crate) struct Store #[derive(Clone)] #[cfg(not(feature = "std"))] -pub(crate) struct Store -{ +pub(crate) struct Store { pub map: IndexMap, // Stores the items and assign them an index pub heap: Vec, // Implements the heap of indexes pub qp: Vec, // Performs the translation from the index @@ -176,7 +174,9 @@ impl Store { self.qp.clear(); self.size = 0; - Drain{iter: self.map.drain(..)} + Drain { + iter: self.map.drain(..), + } } /// Returns the number of elements the internal map can hold without @@ -419,8 +419,7 @@ where } } -impl IntoIterator for Store -{ +impl IntoIterator for Store { type Item = (I, P); type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { @@ -430,8 +429,7 @@ impl IntoIterator for Store } } -impl<'a, I, P, H> IntoIterator for &'a Store -{ +impl<'a, I, P, H> IntoIterator for &'a Store { type Item = (&'a I, &'a P); type IntoIter = Iter<'a, I, P>; fn into_iter(self) -> Iter<'a, I, P> { @@ -565,8 +563,7 @@ mod serde { use serde::ser::{Serialize, SerializeSeq, Serializer}; - impl Serialize for Store - { + impl Serialize for Store { fn serialize(&self, serializer: S) -> Result where S: Serializer, diff --git a/tests/double_priority_queue.rs b/tests/double_priority_queue.rs index 85c699a..149de1e 100644 --- a/tests/double_priority_queue.rs +++ b/tests/double_priority_queue.rs @@ -361,7 +361,6 @@ mod doublepq_tests { assert_eq!(queue.pop_max(), None); } - #[test] fn extend() { let mut pq = DoublePriorityQueue::new();