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 19c2287
Showing 1 changed file with 6 additions and 9 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

0 comments on commit 19c2287

Please sign in to comment.