Skip to content

Commit

Permalink
Use Associated method syntax in macros to avoid infinite recursion lint
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-gabriel committed May 10, 2024
1 parent 6a235be commit fa6adbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
15 changes: 6 additions & 9 deletions omniqueue/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ macro_rules! impl_queue_consumer {
$ident:ident $( <$ty:ident: $tr:path> )?,
$payload:ty
) => {
#[deny(unconditional_recursion)] // method calls must defer to inherent methods
impl<$($ty: $tr)?> crate::QueueConsumer for $ident<$($ty)?> {
type Payload = $payload;

fn receive(&mut self) -> impl std::future::Future<Output = Result<Delivery>> + Send {
self.receive()
$ident::receive(self)
}

fn receive_all(
&mut self,
max_messages: usize,
deadline: Duration,
) -> impl std::future::Future<Output = Result<Vec<Delivery>>> + Send {
self.receive_all(max_messages, deadline)
$ident::receive_all(self, max_messages, deadline)
}
}
};
Expand All @@ -27,22 +26,21 @@ macro_rules! impl_queue_producer {
$ident:ident $( <$ty:ident: $tr:path> )?,
$payload:ty
) => {
#[deny(unconditional_recursion)] // method calls must defer to inherent methods
impl<$($ty: $tr)?> crate::QueueProducer for $ident<$($ty)?> {
type Payload = $payload;

fn send_raw(
&self,
payload: &Self::Payload,
) -> impl std::future::Future<Output = Result<()>> + Send {
self.send_raw(payload)
$ident::send_raw(self, payload)
}

fn send_serde_json<P: serde::Serialize + Sync>(
&self,
payload: &P,
) -> impl std::future::Future<Output = Result<()>> + Send {
self.send_serde_json(payload)
$ident::send_serde_json(self, payload)
}
}
};
Expand All @@ -53,22 +51,21 @@ macro_rules! impl_scheduled_queue_producer {
$ident:ident $( <$ty:ident: $tr:path> )?,
$payload:ty
) => {
#[deny(unconditional_recursion)] // method calls must defer to inherent methods
impl<$($ty: $tr)?> crate::ScheduledQueueProducer for $ident<$($ty)?> {
fn send_raw_scheduled(
&self,
payload: &Self::Payload,
delay: Duration,
) -> impl std::future::Future<Output = Result<()>> + Send {
self.send_raw_scheduled(payload, delay)
$ident::send_raw_scheduled(self, payload, delay)
}

fn send_serde_json_scheduled<P: serde::Serialize + Sync>(
&self,
payload: &P,
delay: Duration,
) -> impl std::future::Future<Output = Result<()>> + Send {
self.send_serde_json_scheduled(payload, delay)
$ident::send_serde_json_scheduled(self, payload, delay)
}
}
};
Expand Down
16 changes: 8 additions & 8 deletions omniqueue/tests/it/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn make_test_queue() -> QueueBuilder<SqsBackend> {
#[tokio::test]
async fn test_raw_send_recv() {
let payload = "{\"test\": \"data\"}";
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_raw(payload).await.unwrap();

Expand All @@ -63,7 +63,7 @@ async fn test_bytes_send_recv() {
use omniqueue::QueueProducer as _;

let payload = b"hello";
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_bytes(payload).await.unwrap();

Expand All @@ -80,7 +80,7 @@ pub struct ExType {
#[tokio::test]
async fn test_serde_send_recv() {
let payload = ExType { a: 2 };
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_serde_json(&payload).await.unwrap();

Expand All @@ -94,7 +94,7 @@ async fn test_serde_send_recv() {
#[tokio::test]
async fn test_send_recv_all_partial() {
let payload = ExType { a: 2 };
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_serde_json(&payload).await.unwrap();
let deadline = Duration::from_secs(1);
Expand All @@ -114,7 +114,7 @@ async fn test_send_recv_all_partial() {
async fn test_send_recv_all_full() {
let payload1 = ExType { a: 1 };
let payload2 = ExType { a: 2 };
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_serde_json(&payload1).await.unwrap();
p.send_serde_json(&payload2).await.unwrap();
Expand Down Expand Up @@ -148,7 +148,7 @@ async fn test_send_recv_all_full_then_partial() {
let payload1 = ExType { a: 1 };
let payload2 = ExType { a: 2 };
let payload3 = ExType { a: 3 };
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

p.send_serde_json(&payload1).await.unwrap();
p.send_serde_json(&payload2).await.unwrap();
Expand Down Expand Up @@ -189,7 +189,7 @@ async fn test_send_recv_all_full_then_partial() {
/// Consumer will NOT wait indefinitely for at least one item.
#[tokio::test]
async fn test_send_recv_all_late_arriving_items() {
let (_p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (_p, c) = make_test_queue().await.build_pair().await.unwrap();

let deadline = Duration::from_secs(1);
let now = Instant::now();
Expand All @@ -205,7 +205,7 @@ async fn test_send_recv_all_late_arriving_items() {
#[tokio::test]
async fn test_scheduled() {
let payload1 = ExType { a: 1 };
let (p, mut c) = make_test_queue().await.build_pair().await.unwrap();
let (p, c) = make_test_queue().await.build_pair().await.unwrap();

let delay = Duration::from_secs(3);
let now = Instant::now();
Expand Down

0 comments on commit fa6adbc

Please sign in to comment.