From 1a634fc29b2238fffbbf71e8db7771c172ad750f Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sat, 30 Mar 2024 21:50:08 +0000 Subject: [PATCH] Fix formatting --- serial_test/src/parallel_code_lock.rs | 10 ++++++---- serial_test/src/rwlock.rs | 23 +++++++++++++---------- serial_test/src/serial_code_lock.rs | 6 +++++- serial_test_test/src/lib.rs | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/serial_test/src/parallel_code_lock.rs b/serial_test/src/parallel_code_lock.rs index a474365..fe47e0f 100644 --- a/serial_test/src/parallel_code_lock.rs +++ b/serial_test/src/parallel_code_lock.rs @@ -5,14 +5,16 @@ use crate::code_lock::{check_new_key, global_locks}; use futures::FutureExt; use std::panic; -fn get_locks( - names: Vec<&str>, -) -> Vec { +fn get_locks(names: Vec<&str>) -> Vec { names .into_iter() .map(|name| { check_new_key(name); - global_locks().get(name).expect("key to be set").get().clone() + global_locks() + .get(name) + .expect("key to be set") + .get() + .clone() }) .collect::>() } diff --git a/serial_test/src/rwlock.rs b/serial_test/src/rwlock.rs index f2e5376..3d0cd27 100644 --- a/serial_test/src/rwlock.rs +++ b/serial_test/src/rwlock.rs @@ -1,7 +1,7 @@ -use parking_lot::{Condvar, Mutex, ReentrantMutex, ReentrantMutexGuard}; -use std::{sync::Arc, time::Duration}; #[cfg(feature = "logging")] use log::debug; +use parking_lot::{Condvar, Mutex, ReentrantMutex, ReentrantMutexGuard}; +use std::{sync::Arc, time::Duration}; struct LockState { parallels: u32, @@ -18,7 +18,7 @@ pub(crate) struct Locks { arc: Arc, // Name we're locking for (mostly test usage) #[cfg(feature = "logging")] - pub(crate) name: String + pub(crate) name: String, } pub(crate) struct MutexGuardWrapper<'a> { @@ -44,7 +44,7 @@ impl Locks { serial: Default::default(), }), #[cfg(feature = "logging")] - name: name.to_owned() + name: name.to_owned(), } } @@ -55,7 +55,7 @@ impl Locks { pub fn serial(&self) -> MutexGuardWrapper { #[cfg(feature = "logging")] - debug!("Get serial lock '{}'", self.name); + debug!("Get serial lock '{}'", self.name); let mut lock_state = self.arc.mutex.lock(); loop { #[cfg(feature = "logging")] @@ -65,14 +65,14 @@ impl Locks { let possible_serial_lock = self.arc.serial.try_lock(); if let Some(serial_lock) = possible_serial_lock { #[cfg(feature = "logging")] - debug!("Got serial '{}'", self.name); + debug!("Got serial '{}'", self.name); return MutexGuardWrapper { mutex_guard: serial_lock, locks: self.clone(), }; } else { #[cfg(feature = "logging")] - debug!("Someone else has serial '{}'", self.name); + debug!("Someone else has serial '{}'", self.name); } } @@ -88,7 +88,10 @@ impl Locks { let mut lock_state = self.arc.mutex.lock(); loop { #[cfg(feature = "logging")] - debug!("Parallel, existing {} '{}'", lock_state.parallels, self.name); + debug!( + "Parallel, existing {} '{}'", + lock_state.parallels, self.name + ); if lock_state.parallels > 0 { // fast path, as someone else already has it locked lock_state.parallels += 1; @@ -98,7 +101,7 @@ impl Locks { let possible_serial_lock = self.arc.serial.try_lock(); if possible_serial_lock.is_some() { #[cfg(feature = "logging")] - debug!("Parallel first '{}'", self.name); + debug!("Parallel first '{}'", self.name); // We now know no-one else has the serial lock, so we can add to parallel lock_state.parallels = 1; // Had to have been 0 before, as otherwise we'd have hit the fast path return; @@ -114,7 +117,7 @@ impl Locks { pub fn end_parallel(&self) { #[cfg(feature = "logging")] - debug!("End parallel"); + debug!("End parallel"); let mut lock_state = self.arc.mutex.lock(); assert!(lock_state.parallels > 0); lock_state.parallels -= 1; diff --git a/serial_test/src/serial_code_lock.rs b/serial_test/src/serial_code_lock.rs index 2a270b9..b02475e 100644 --- a/serial_test/src/serial_code_lock.rs +++ b/serial_test/src/serial_code_lock.rs @@ -9,7 +9,11 @@ macro_rules! core_internal { .into_iter() .map(|name| { check_new_key(name); - global_locks().get(name).expect("key to be set").get().clone() + global_locks() + .get(name) + .expect("key to be set") + .get() + .clone() }) .collect(); let _guards: Vec<_> = unlocks.iter().map(|unlock| unlock.lock()).collect(); diff --git a/serial_test_test/src/lib.rs b/serial_test_test/src/lib.rs index 1e63d11..5fa70d1 100644 --- a/serial_test_test/src/lib.rs +++ b/serial_test_test/src/lib.rs @@ -36,6 +36,7 @@ //! fn main() {} //! ``` +use log::info; #[cfg(test)] use serial_test::{parallel, serial}; use std::{ @@ -45,7 +46,6 @@ use std::{ thread, time::Duration, }; -use log::info; static LOCK: AtomicUsize = AtomicUsize::new(0);