From bfed19e6ad82976b76dea0a4129dd241f26c7089 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 24 May 2025 16:34:09 +0200 Subject: [PATCH] refactor(stub): always use std Mutex (#1091) --- src/transport/stub/mod.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/transport/stub/mod.rs b/src/transport/stub/mod.rs index a76bceb..d9546fb 100644 --- a/src/transport/stub/mod.rs +++ b/src/transport/stub/mod.rs @@ -43,13 +43,11 @@ use std::{ error::Error as StdError, fmt, - sync::{Arc, Mutex as StdMutex}, + sync::{Arc, Mutex}, }; #[cfg(any(feature = "tokio1", feature = "async-std1"))] use async_trait::async_trait; -#[cfg(any(feature = "tokio1", feature = "async-std1"))] -use futures_util::lock::Mutex as FuturesMutex; #[cfg(any(feature = "tokio1", feature = "async-std1"))] use crate::AsyncTransport; @@ -72,7 +70,7 @@ impl StdError for Error {} #[derive(Debug, Clone)] pub struct StubTransport { response: Result<(), Error>, - message_log: Arc>>, + message_log: Arc>>, } /// This transport logs messages and always returns the given response @@ -81,7 +79,7 @@ pub struct StubTransport { #[cfg_attr(docsrs, doc(cfg(any(feature = "tokio1", feature = "async-std1"))))] pub struct AsyncStubTransport { response: Result<(), Error>, - message_log: Arc>>, + message_log: Arc>>, } impl StubTransport { @@ -89,7 +87,7 @@ impl StubTransport { pub fn new(response: Result<(), Error>) -> Self { Self { response, - message_log: Arc::new(StdMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } @@ -97,7 +95,7 @@ impl StubTransport { pub fn new_ok() -> Self { Self { response: Ok(()), - message_log: Arc::new(StdMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } @@ -105,7 +103,7 @@ impl StubTransport { pub fn new_error() -> Self { Self { response: Err(Error), - message_log: Arc::new(StdMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } @@ -124,7 +122,7 @@ impl AsyncStubTransport { pub fn new(response: Result<(), Error>) -> Self { Self { response, - message_log: Arc::new(FuturesMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } @@ -132,7 +130,7 @@ impl AsyncStubTransport { pub fn new_ok() -> Self { Self { response: Ok(()), - message_log: Arc::new(FuturesMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } @@ -140,14 +138,14 @@ impl AsyncStubTransport { pub fn new_error() -> Self { Self { response: Err(Error), - message_log: Arc::new(FuturesMutex::new(vec![])), + message_log: Arc::new(Mutex::new(vec![])), } } /// Return all logged messages sent using [`AsyncTransport::send_raw`] #[cfg(any(feature = "tokio1", feature = "async-std1"))] pub async fn messages(&self) -> Vec<(Envelope, String)> { - self.message_log.lock().await.clone() + self.message_log.lock().unwrap().clone() } } @@ -173,7 +171,7 @@ impl AsyncTransport for AsyncStubTransport { async fn send_raw(&self, envelope: &Envelope, email: &[u8]) -> Result { self.message_log .lock() - .await + .unwrap() .push((envelope.clone(), String::from_utf8_lossy(email).into())); self.response }